Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

List Box Question

Status
Not open for further replies.

DarkMercenary44

Technical User
May 19, 2000
55
US
How can I make 8 list boxes link to each other so that I only have to use the scroll bar on one of them, can I do this without the delay that a timer makes. And how do I make it so that with anyone of them if I click on something it highlights the corresponding item in the other 7 boxes.

If thats to hard for you to answer then try this it may be easier , how can I make columns in a list box.

And the last question is , how can I make alternating rows of color on a normal list box, I can do it with the SBList custom control, but I have to pay for that one, and I'm just making freeware so why buy it.
 
Answer to Question 1:

Add two listboxs to a form and call them lstMain and lstAlt, then past this code in the form and run it. Be sure you make both listboxs about 1 inch high or you won't get the scroll bars.

Option Explicit

Private Sub Form_Load()
lstMain.AddItem "Steve"
lstMain.AddItem "John"
lstMain.AddItem "Andy"
lstMain.AddItem "Bob"
lstMain.AddItem "Nancy"
lstMain.AddItem "Melissa"
lstMain.AddItem "Scott"
lstMain.AddItem "Linda"
lstMain.AddItem "Barb"
lstMain.AddItem "Lori"

lstAlt.AddItem "Steve"
lstAlt.AddItem "John"
lstAlt.AddItem "Andy"
lstAlt.AddItem "Bob"
lstAlt.AddItem "Nancy"
lstAlt.AddItem "Melissa"
lstAlt.AddItem "Scott"
lstAlt.AddItem "Linda"
lstAlt.AddItem "Barb"
lstAlt.AddItem "Lori"

End Sub

Private Sub lstMain_Click()
lstAlt.Selected(lstMain.ListIndex) = True
End Sub

Private Sub lstMain_Scroll()
lstAlt.TopIndex = lstMain.TopIndex
End Sub

Private Sub lstAlt_Click()
lstMain.Selected(lstAlt.ListIndex) = True
End Sub

Private Sub lstAlt_Scroll()
lstMain.TopIndex = lstAlt.TopIndex
End Sub

Answer to question 2:

If you want to create columns in a listbox then you can concatentate the data together using vbTab. If your data hase variying lengths that go over tab boundries, then you'll have to have an additional routine to determine how many tabs to insert before adding the item to the listbox. Or you can use the API to set the tab column after you add the data using the code from here:


Answer to question 3:

I don't think this can be done with a listbox. I know you can change the colors of a ListView control because the control allows for it. I don't beleve the standard listbox that ships with Visual BASIC allows you to do this.

Ah heck, 2 out of 3 ain't bad...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top