hatman
Well-known Member
- Joined
- Apr 8, 2005
- Messages
- 2,664
I have two lists that represent pairs of electrical connectors. List_1 is Male Connectors, and List_2 is the mating Female Connectors. The lists are built so that when side-by-side, a mating pair line up next to each other.
I'm trying to build a User Interface that presents the connectors as pairs, but also aloow the user to select EITHER member of the pair.
My first thougt was to use a Listview or a Listbox with 2 columns. Either way, the user selects a full row, rather a single entry in a row.
I finally ended up building a userform with 2 Listboxes adjacent to each other, and a Vertical Scrollbar Control to the right of the pair. I added the following code to the form, to scroll both Listboxes simultaneously:
As far as that goes, it works fairly well. The user scrolls up and down using the Scrollbar control, and paired entries remain adjacent to each other. The user can select an entry from either Listbox, and I can easily harvest that choice through code.
I was hoping, however, that I could support people who use the keyboard for navigation. Focus on one of the Listboxes, then navigate using the up and down arrow keys. When the user gets to the end of the list, the value of the Scrollbar control increments or decrements as required, thus re-populating the lists. I just can't get this to work in a way that is not cludgey. I have worked through about a half-dozen possible methods, and each one has some hitch that makes it either hokey or unworkable.
Has anyone done this successfully, or have any suggestions to make it work?
I'm trying to build a User Interface that presents the connectors as pairs, but also aloow the user to select EITHER member of the pair.
My first thougt was to use a Listview or a Listbox with 2 columns. Either way, the user selects a full row, rather a single entry in a row.
I finally ended up building a userform with 2 Listboxes adjacent to each other, and a Vertical Scrollbar Control to the right of the pair. I added the following code to the form, to scroll both Listboxes simultaneously:
Code:
Private Const Display_Lines As Long = 7
Private Sub ListBox1_Click()
Me.ListBox2.ListIndex = -1
End Sub
Private Sub ListBox2_Click()
Me.ListBox1.ListIndex = -1
End Sub
Private Sub ScrollBar1_Change()
Me.ListBox1.Clear
Me.ListBox2.Clear
For cnt = Me.ScrollBar1.Value To Me.ScrollBar1.Value + Display_Lines - 1
Me.ListBox1.AddItem Range("List_1").Item(cnt).Value
Me.ListBox2.AddItem Range("List_2").Item(cnt).Value
Next cnt
End Sub
Private Sub UserForm_Initialize()
Me.ScrollBar1.Min = 1
Me.ScrollBar1.Max = Range("List_1").Count - Display_Lines + 1
Me.ScrollBar1.LargeChange = Me.ScrollBar1.Max / 5
Me.ScrollBar1.Value = 1
End Sub
As far as that goes, it works fairly well. The user scrolls up and down using the Scrollbar control, and paired entries remain adjacent to each other. The user can select an entry from either Listbox, and I can easily harvest that choice through code.
I was hoping, however, that I could support people who use the keyboard for navigation. Focus on one of the Listboxes, then navigate using the up and down arrow keys. When the user gets to the end of the list, the value of the Scrollbar control increments or decrements as required, thus re-populating the lists. I just can't get this to work in a way that is not cludgey. I have worked through about a half-dozen possible methods, and each one has some hitch that makes it either hokey or unworkable.
Has anyone done this successfully, or have any suggestions to make it work?