943,095 Members | Top Members by Rank

Ad:
Jan 21st, 2010
0

Tree View Multi Select

Expand Post »
Hi guys
I need your help a bit.
I have designed a tree view control and the user can select multiple options.
Now the problem lies in:
"When the user clicks on show button a msgbox appears showing all the items selected"....This is what I want to do. but is clueless on how to do.
Please help me out ASAP
Thank You in advance
Similar Threads
Reputation Points: 10
Solved Threads: 3
Junior Poster
ankush.mukherje is offline Offline
109 posts
since Jan 2010
Jan 21st, 2010
0
Re: Tree View Multi Select
What does tv1.SelectedItem.Key returns ?
Featured Poster
Reputation Points: 665
Solved Threads: 427
Posting Genius
debasisdas is offline Offline
6,402 posts
since Feb 2007
Jan 21st, 2010
0
Re: Tree View Multi Select
Hi
tv1.selecteditem.key returns nothing but a blank msgbox.
I had already tried it.
Is there any other option?
Reputation Points: 10
Solved Threads: 3
Junior Poster
ankush.mukherje is offline Offline
109 posts
since Jan 2010
Jan 21st, 2010
0
Re: Tree View Multi Select
Hi
common man....isn't there any one who can help me out?
Reputation Points: 10
Solved Threads: 3
Junior Poster
ankush.mukherje is offline Offline
109 posts
since Jan 2010
Jan 21st, 2010
1
Re: Tree View Multi Select
You will have to enumerate through the nodes to find out which ones have been selected and if they have then retrieve the information you want from them...
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Option Explicit
  2.  
  3. Private Sub Form_Load()
  4. Dim N As Node
  5. Set N = TV.Nodes.Add(, , "Root1", "Root1")
  6. Set N = TV.Nodes.Add(, , "Root2", "Root2")
  7. Set N = TV.Nodes.Add(, , "Root3", "Root3")
  8. Set N = TV.Nodes.Add(, , "Root4", "Root4")
  9.  
  10. End Sub
  11.  
  12. Private Sub Command1_Click()
  13. Dim N As Node, ForLoopCounter As Integer
  14.  
  15. For ForLoopCounter = 1 To TV.Nodes.Count
  16. If TV.Nodes(ForLoopCounter).Selected = True Then
  17. MsgBox TV.Nodes(ForLoopCounter).Key
  18. End If
  19. Next ForLoopCounter
  20.  
  21. For Each N In TV.Nodes
  22. If N.Checked = True Then
  23. MsgBox N.Text
  24. End If
  25. Next N
  26. End Sub

Now, as you can see, if you are using check boxes (as I set mine up to have), the checked property is different than the selected propert and as you can see, I have shown you two different ways in which to enumerate through the items in a treeview control...



Good Luck
Reputation Points: 156
Solved Threads: 296
Posting Virtuoso
vb5prgrmr is offline Offline
1,670 posts
since Mar 2009
Jan 21st, 2010
1
Re: Tree View Multi Select
Hi, Ankush!

So, if you don't explicit a value for the key when you load your TreeView control, it will return empty if you test.

Take a look:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. 'TreeView1.Nodes.Add Relative, Relationship, Key, Text, Image, ImageSelected
  2. TreeView1.Nodes.Add , , , "Texto1"
  3. TreeView1.Nodes.Add , , "K01", "Texto2"

If you put the code MsgBox TreeView1.SelectedItem.Key in a button, if user select the first option and click the button, the dialog box shows empty; if the user select the second option and click button again, the dialog box will show "K01".
It means that you aren't filling the key property in your treeview control.


So, I'm thinking in your problem and maybe the key property would help you to code what you want.
If you use the primary key field in this property, you easily select the match option in any other control(s). Don't forget to use a letter at first in the key property - for example, if your primary key is an integer value, you should put "K" and then the primary key value, like TreeView1.Nodes.Add , , "K" & oDados.Fields("YOURPRIMARYKEY").Value, oDados.Fields("TheFieldYouWantUserToSee").Value ...


And, for my information, what property you change to made TreeView multiselectable? In my tests, I can't find this functionality, until I changed to turn checkboxes on...


Regards!

Sidnei



Hi
tv1.selecteditem.key returns nothing but a blank msgbox.
I had already tried it.
Is there any other option?
Reputation Points: 22
Solved Threads: 10
Junior Poster in Training
sidnei is offline Offline
55 posts
since Dec 2009
Jan 21st, 2010
0
Re: Tree View Multi Select
Quote ...
Originally quote by sidnei:
And, for my information, what property you change to made TreeView multiselectable? In my tests, I can't find this functionality, until I changed to turn checkboxes on...
This is the coding I have done for multiselection:

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub tvwNodeSelect(Optional Node As Node)
  2. Dim i As Long
  3. Dim selNode As Node
  4. Dim tvwnodecol As Collection
  5. If blCtrlSel Then
  6. If Node.BackColor = vbHighlight Then
  7. If tvwnodecol.Count > 1 Then
  8. Node.BackColor = vbWindowBackground
  9. Node.ForeColor = vbWindowText
  10. Node.Selected = False
  11. tvwnodecol.Remove Node.Key
  12. End If
  13. Exit Sub
  14. End If
  15. End If
  16.  
  17. If Not Node Is Nothing Then
  18. Node.BackColor = vbRed
  19. Node.ForeColor = vbBlack
  20. MsgBox (Node.Text)
  21. End If
  22. End Sub
Reputation Points: 10
Solved Threads: 3
Junior Poster
ankush.mukherje is offline Offline
109 posts
since Jan 2010
Jan 21st, 2010
0
Re: Tree View Multi Select
Hi vb5prgrmr
I think I was not clear in my text.
By the way thanks a lot for your help
What I want is the user first makes the selection and then all the selections he has made appear in a text box.
Thanks in advance
Reputation Points: 10
Solved Threads: 3
Junior Poster
ankush.mukherje is offline Offline
109 posts
since Jan 2010
Jan 22nd, 2010
0
Re: Tree View Multi Select
Well with the code I have provided, you should be able to figure it out...



Good Luck
Reputation Points: 156
Solved Threads: 296
Posting Virtuoso
vb5prgrmr is offline Offline
1,670 posts
since Mar 2009
Jan 22nd, 2010
0
Re: Tree View Multi Select
Hi vb5prgrmr
Thanks
I will go through it again
Reputation Points: 10
Solved Threads: 3
Junior Poster
ankush.mukherje is offline Offline
109 posts
since Jan 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Changing orientation within a page
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: how to put message box "not found"





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC