Selecting from ListBox

Selecting from ListBox

Anonymous
Not applicable
548 Views
6 Replies
Message 1 of 7

Selecting from ListBox

Anonymous
Not applicable
Hi, all. Happy New Year.

Rather like "Undo" on the Standard toolbar (when displayed horizontally!) I would like to have a ListBox in a userform that has the top item selected; when the user picks, for example, item 4 from the list all intermediate items from the top down are also selected. Is this (easily) possible?

S
0 Likes
549 Views
6 Replies
Replies (6)
Message 2 of 7

fxcastil
Advocate
Advocate
see attached

Fred Castillo
0 Likes
Message 3 of 7

Anonymous
Not applicable
Fred,

Thanks for your reply. Although your LISTBOX does what's required if I double-click an item of the list I can still deselect an item between the top one and my initial selection. This can't be allowed as all items in the list are related... item 5 can't proceed without items 1 through 4 happening first. Therefore if my second selection is item 3 then items 1, 2 and 3 remain selected and items 4 and 5 are deselected.

I've tried modifying your 'ListBox1_DblClick' sub but haven't got anywhere with it yet.

S
0 Likes
Message 4 of 7

Anonymous
Not applicable
Try this....

Private Sub ListBox1_Mouseup(ByVal Button As Integer, ByVal Shift As
Integer, ByVal X As Single, ByVal Y As Single)
Dim I As Integer
Dim J As Integer
With ListBox1
I = .ListIndex
For J = 0 To .ListCount - 1
.Selected(J) = False
Next
For J = 0 To I
.Selected(J) = True
Next
End With
End Sub

wrote in message news:5053589@discussion.autodesk.com...
Fred,

Thanks for your reply. Although your LISTBOX does what's required if I
double-click an item of the list I can still deselect an item between the
top one and my initial selection. This can't be allowed as all items in the
list are related... item 5 can't proceed without items 1 through 4 happening
first. Therefore if my second selection is item 3 then items 1, 2 and 3
remain selected and items 4 and 5 are deselected.

I've tried modifying your 'ListBox1_DblClick' sub but haven't got anywhere
with it yet.

S
0 Likes
Message 5 of 7

Anonymous
Not applicable
Jeff,

I think I can see what this code is supposed to do - deselect everything then reselect 0 > i - but nothing is happening. Just single selections...?

S
0 Likes
Message 6 of 7

Anonymous
Not applicable
To yake it a step further, this allows the deselection of an item and also
allows the use of keyboard entry.

Option Explicit

Private Sub ListBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
List_Select ListBox1
End Sub

Private Sub ListBox1_Mouseup(ByVal Button As Integer, ByVal Shift As
Integer, ByVal X As Single, ByVal Y As Single)
List_Select ListBox1
End Sub

Private Sub UserForm_Initialize()
Dim I As Integer
For I = 0 To 10
ListBox1.AddItem "Item " & I
Next
ListBox1.MultiSelect = fmMultiSelectMulti
End Sub

Function List_Select(ListBox As ListBox)
Dim I As Integer
Dim J As Integer
With ListBox
I = .ListIndex
If .Selected(I) = True Then
For J = 0 To .ListCount - 1
.Selected(J) = False
Next
For J = 0 To I
.Selected(J) = True
Next
Else
For J = I To .ListCount - 1
.Selected(J) = False
Next
End If
End With
End Function


"Jeff Mishler" wrote in message
news:5053577@discussion.autodesk.com...
Try this....
0 Likes
Message 7 of 7

Anonymous
Not applicable
Now that one did the business! Thanks, Jeff.

S
0 Likes