CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2016
    Posts
    1

    Treeview and listbox query

    Hi,
    I do have a treeview, commandButton and listbox. The treeview has 5 nodes, and each node has more than 10 childs. I want to know how can I add the selected item from treeview to the listbox with the click the commandbutton1 to display the result into listbox.? But the node that is already there in the listbox should not be added again into the list box from treeview. And there is another commandbutton2 from which I can remove the selected node from listbox.
    And is there any way how I can enable or disable the commandbutton1 if I have selected node from Treeview and commandbutton2 if I have selected from listbox.
    And only five nodes I can select.

    Below is code that I have added for adding from treeview to listbox:

    Private Sub cmdAdd_click()
    Dim N As Node
    For Each N In TreeView1.Nodes
    If N.Selected Then
    If List1.ListCount > 4 Then
    MsgBox "You can select upto 5 Ethnicity"
    Else
    List1.AddItem N.Text
    End If
    End If
    Next
    End Sub

    Please help me!!!!!
    Thank you,

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Treeview and listbox query

    In order to obtain the selected node you could do something in the lines of :

    Code:
    IF tv.Nodes.Item(3).Selected THEN
    To enable/disable any object you should make use of the .Enabled property of the desired object

    I hope this helps!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured