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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Line between List Boxes - How?

Status
Not open for further replies.

origapizni

Programmer
Aug 2, 2001
29
0
0
US
A user asked me: " would like to visually link items in two list boxes similar to the way the QBE interface in MS Access works. Does anyone have any ideas on how to do this?"

In other words, 2 list boxes connected by a line which links a single item in one list with a related item in the other.

Has anyone ever seen this done in VB? Code or a reference to a 3rd-party tool would be great!

TIA
 
hehehe Hmmm you'd have to subclass the list boxes to get at the Y coord of the list item inside the list index. Then its pretty easy to have line draw between
Listbox1.Left + Listbox1.width, Listbox1.top + Listbox1.Item().Y to Listbox2.Left + Listbox2.width, Listbox2.top + Listbox2.Item().Y

or you could you the ListView instead of the listbox. This has alot more functionality to include the ability to grab the top,left,height and width of an individual listitem.
 
here is some code as a starting example.
Create a project and just drop 2 ListViews on a form

Code:
Option Explicit

Dim b1 As Integer
Dim b2 As Integer
Private Sub Form_Load()
    Dim I As Integer
    For I = 1 To 30
        ListView1.ListItems.Add , "C" & CStr(I), "TEST " & CStr(I)
        ListView2.ListItems.Add , "C" & CStr(I), "TEST " & CStr(I)
    Next
    b1 = 1
    b2 = 1
End Sub

Private Sub Form_Paint()
    Me.Line (ListView1.Left + ListView1.Width, ListView1.Top + ListView1.ListItems(b1).Top + (ListView1.ListItems(b1).Height / 2))-(ListView2.Left, ListView2.Top + ListView2.ListItems(b2).Top + (ListView2.ListItems(b2).Height / 2)), RGB(255, 0, 0)
End Sub

Private Sub ListView1_Click()
    If Not ListView1.SelectedItem Is Nothing Then
        b1 = ListView1.SelectedItem.Index
    End If
    Me.Refresh
End Sub


Private Sub ListView2_Click()
    If Not ListView2.SelectedItem Is Nothing Then
        b21 = ListView2.SelectedItem.Index
    End If
    Me.Refresh
End Sub
 
Thanks SemperFi. I have more questions. First, I need to clarify the requirement a little (sorry...)

My user wants connected list boxes like you see in the Access query design window, where there is a line connecting 2 tables visually showing the SQL Joins. To make it harder, the lines, as you know, remain "stuck" to the selections and move as you scroll or drag the boxes around the screen. He probably won't be having the users move the list boxes around on the form, but "sticking" while scrolling is important.

Does your sample move the line during scrolling?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top