Link to home
Start Free TrialLog in
Avatar of mkumaraguru49
mkumaraguru49

asked on

Draw Line between two Listbox items (line may be one to many relationship)

I want to draw lines between two listbox items, the mapping relationship might be one-to-one, or one-to-many, or many-to-one relationship.  

User want to do drag and drop listbox items and draw line between the items.  I need sampe code uisng vb.net


ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mkumaraguru49
mkumaraguru49

ASKER

Hi
The code is working fine.  but i want to move the lines (drawn between 2 list box)  when user scroll the list box...

what should i do ...

Thanks for yr support
I thought I had done that already....

I specifically wrote this small helper class to trap the scrolling messages:

    Private Class ListBoxScroll
        Inherits NativeWindow

        Private Const WM_VSCROLL = &H115

        Public Event Scrolled()

        Public Sub New(ByVal lb As ListBox)
            Me.AssignHandle(lb.Handle)
        End Sub

        Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
            If m.Msg = WM_VSCROLL Then
                RaiseEvent Scrolled()
            End If

            MyBase.WndProc(m)
        End Sub

    End Class

and then I updated the lines whenever the ListBoxes were scrolled.  If it's not working for you, please let me know what version VB.Net and version Windows you are working with.
Hi
I don't know that how to use this helper class.   Could you please explain, how to use it, otherwise, give me a full sample code of this.
thank you
The code in the link IS a FULL, WORKING example...  =\

The helper class is being created in the Load() event of the Form:

    Private WithEvents lbs1 As ListBoxScroll
    Private WithEvents lbs2 As ListBoxScroll

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        lbs1 = New ListBoxScroll(Me.ListBox1)
        lbs2 = New ListBoxScroll(Me.ListBox2)
    End Sub

    Private Sub lbs1_Scrolled() Handles lbs1.Scrolled
        Panel1.Refresh()
    End Sub

    Private Sub lbs2_Scrolled() Handles lbs2.Scrolled
        Panel1.Refresh()
    End Sub
It is really very helpful.