|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Help - Single-Select with Listbox...Good day can I select only one row of a listbox with the syle checkbox?
Any help would be greatly appreciated. Thanks! "Lisa" <rford***@hotmail.com> wrote in message Seems very odd to use checkboxes but only allow 1 single selection but younews:11kr00oti38p792@corp.supernews.com > Good day can I select only one row of a listbox with the syle > checkbox? can always handle it with a brute-force approach: Private Sub List1_Click() Dim x As Long If List1.Selected(List1.ListIndex) Then For x = 0 To List1.ListCount - 1 List1.Selected(x) = (x = List1.ListIndex) Next End If End Sub -- Reply to the group so all can participate VB.Net: "Fool me once..." "Lisa" <rford***@hotmail.com> wrote in message Hi Lisa -news:11kr00oti38p792@corp.supernews.com... > Good day can I select only one row of a listbox with the syle checkbox? > > Any help would be greatly appreciated. > > Thanks! > > If I understand your question correctly maybe this hack will do what you want. Someone else may have a better way but I have used this technique in at least one of my projects. Private Sub Form_Load() With List1 .AddItem "Item 1" .AddItem "Item 2" .AddItem "Item 3" .AddItem "Item 4" End With End Sub Private Sub List1_ItemCheck(Item As Integer) Dim iCnt As Integer For iCnt = 0 To List1.ListCount - 1 If iCnt <> Item Then List1.Selected(iCnt) = False End If Next End Sub Jim Edgar
Show quote
Hide quote
> > Good day can I select only one row of a listbox with the syle You might have to modify this a little bit. Run your code, selectcheckbox? > > > > Any help would be greatly appreciated. > > > > Thanks! > > > > > > Hi Lisa - > > If I understand your question correctly maybe this hack will do what you > want. Someone else may have a better way but I have used this technique in > at least one of my projects. > > Private Sub Form_Load() > With List1 > .AddItem "Item 1" > .AddItem "Item 2" > .AddItem "Item 3" > .AddItem "Item 4" > End With > End Sub > > Private Sub List1_ItemCheck(Item As Integer) > Dim iCnt As Integer > For iCnt = 0 To List1.ListCount - 1 > If iCnt <> Item Then > List1.Selected(iCnt) = False > End If > Next > End Sub an item with the mouse then use the arrow key to move the highlight to a different item and press the Space Bar. Bob's code works correctly for this situation, but seems to be a little bit sluggish when clicking from item to item. Rick "Rick Rothstein [MVP - Visual Basic]"
<rickNOSPAMnews@NOSPAMcomcast.net> wrote in message news:Ou56oj3zFHA.3180@TK2MSFTNGP14.phx.gbl Had to get something right today!> You might have to modify this a little bit. Run your code, select > an item with the mouse then use the arrow key to move the > highlight to a different item and press the Space Bar. Bob's code > works correctly for this situation, > but seems to be a little bit Hmmmm... seemed OK here although I didn't use a long list. It'd be possible> sluggish when clicking from item to item. to speed it up by keeping track of the selected item rather than processing the whole list: Private Sub List1_Click() Static FromCode As Boolean Dim n As Long If Not FromCode Then FromCode = True If List1.Selected(List1.ListIndex) Then If Len(List1.Tag) Then n = CLng(List1.Tag) List1.Selected(n) = False End If List1.Tag = CStr(List1.ListIndex) End If FromCode = False End If End Sub -- Reply to the group so all can participate VB.Net: "Fool me once..." Thanks guys. Tell em though. I would ahve liked to use radio buttons instead
but the listbox was the only component I could think of that looked like that. ANy thoughts on similar components? Thanks Show quoteHide quote "Bob Butler" <tiredofit@nospam.com> wrote in message news:O2E61q3zFHA.1168@TK2MSFTNGP15.phx.gbl... > "Rick Rothstein [MVP - Visual Basic]" > <rickNOSPAMnews@NOSPAMcomcast.net> wrote in message > news:Ou56oj3zFHA.3180@TK2MSFTNGP14.phx.gbl > > You might have to modify this a little bit. Run your code, select > > an item with the mouse then use the arrow key to move the > > highlight to a different item and press the Space Bar. Bob's code > > works correctly for this situation, > > Had to get something right today! > > > but seems to be a little bit > > sluggish when clicking from item to item. > > Hmmmm... seemed OK here although I didn't use a long list. It'd be possible > to speed it up by keeping track of the selected item rather than processing > the whole list: > > Private Sub List1_Click() > Static FromCode As Boolean > Dim n As Long > If Not FromCode Then > FromCode = True > If List1.Selected(List1.ListIndex) Then > If Len(List1.Tag) Then > n = CLng(List1.Tag) > List1.Selected(n) = False > End If > List1.Tag = CStr(List1.ListIndex) > End If > FromCode = False > End If > End Sub > > > -- > Reply to the group so all can participate > VB.Net: "Fool me once..." > "Lisa" <rford***@hotmail.com> wrote in message Why not just use a standard listbox with multi-select False? It's the waynews:11kr3igfltaj6fb@corp.supernews.com > Thanks guys. Tell em though. I would ahve liked to use radio buttons > instead but the listbox was the only component I could think of that > looked like that. > most every other app with a need like this works so it'd be immediately understood by the users. There's no need for a radio-button listbox since single-select is already available via highlighting. I'm not even a fan of the checkbox style since it doesn't add anything more to the UI than already exists. -- Reply to the group so all can participate VB.Net: "Fool me once..." Thanks. I needed soemthign like that to help me decide.
Show quoteHide quote "Bob Butler" <tiredofit@nospam.com> wrote in message news:OtHDJ33zFHA.2132@TK2MSFTNGP15.phx.gbl... > "Lisa" <rford***@hotmail.com> wrote in message > news:11kr3igfltaj6fb@corp.supernews.com > > Thanks guys. Tell em though. I would ahve liked to use radio buttons > > instead but the listbox was the only component I could think of that > > looked like that. > > > > Why not just use a standard listbox with multi-select False? It's the way > most every other app with a need like this works so it'd be immediately > understood by the users. There's no need for a radio-button listbox since > single-select is already available via highlighting. I'm not even a fan of > the checkbox style since it doesn't add anything more to the UI than already > exists. > > -- > Reply to the group so all can participate > VB.Net: "Fool me once..." > |
|||||||||||||||||||||||