Treeview + Small Probs

Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Apr 2009
Posts: 33
Reputation: ritu verma is an unknown quantity at this point 
Solved Threads: 1
ritu verma ritu verma is offline Offline
Light Poster

Treeview + Small Probs

 
0
  #1
Jun 13th, 2009
I have a treeview with two nodes..I m showing the contextmenu when the user clicks on any portion of treeview ....

  1. Public Class Form2
  2.  
  3. Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  4. Try
  5.  
  6. Dim N As New TreeNode()
  7. Me.TreeViewCategories.Nodes.Clear()
  8. With Me.TreeViewCategories.Nodes
  9. N = .Add("", "Main", 0)
  10. N.Nodes.Add("", "First Child", 0)
  11. N.Nodes.Add("", "Second Child", 0)
  12. End With
  13. TreeViewCategories.ExpandAll()
  14.  
  15. Catch ex As Exception
  16. MsgBox(ex.Message)
  17. End Try
  18. End Sub
  19.  
  20.  
  21. Private Sub TreeViewCategories_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TreeViewCategories.MouseDown
  22. If e.Button = Windows.Forms.MouseButtons.Right Then
  23. ContextMnuTreeview.Show(TreeViewCategories, e.X, e.Y)
  24. End If
  25. End Sub

Mine probs is that when i right click on Second Child,Contextmenu is showing....But aotomatically root is selected....Y....?Plz copy this code,U will get to know what i want to ask!!!!!!!!!!!
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,581
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 457
Moderator
adatapost's Avatar
adatapost adatapost is online now Online
Posting Maven

Re: Treeview + Small Probs

 
0
  #2
Jun 14th, 2009
Originally Posted by ritu verma View Post
I have a treeview with two nodes..I m showing the contextmenu when the user clicks on any portion of treeview ....

  1. Public Class Form2
  2.  
  3. Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  4. Try
  5.  
  6. Dim N As New TreeNode()
  7. Me.TreeViewCategories.Nodes.Clear()
  8. With Me.TreeViewCategories.Nodes
  9. N = .Add("", "Main", 0)
  10. N.Nodes.Add("", "First Child", 0)
  11. N.Nodes.Add("", "Second Child", 0)
  12. End With
  13. TreeViewCategories.ExpandAll()
  14.  
  15. Catch ex As Exception
  16. MsgBox(ex.Message)
  17. End Try
  18. End Sub
  19.  
  20.  
  21. Private Sub TreeViewCategories_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TreeViewCategories.MouseDown
  22. If e.Button = Windows.Forms.MouseButtons.Right Then
  23. ContextMnuTreeview.Show(TreeViewCategories, e.X, e.Y)
  24. End If
  25. End Sub

Mine probs is that when i right click on Second Child,Contextmenu is showing....But aotomatically root is selected....Y....?Plz copy this code,U will get to know what i want to ask!!!!!!!!!!!
Add Following code

  1. TreeView1.Nodes.Add("Root")
  2. TreeView1.Nodes(0).Nodes.Add("Work")
  3. TreeView1.Nodes(0).Nodes.Add("Play")
  4.  
  5. TreeView1.Nodes(0).Nodes(0).ContextMenuStrip = ContextMenuStrip1
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 33
Reputation: ritu verma is an unknown quantity at this point 
Solved Threads: 1
ritu verma ritu verma is offline Offline
Light Poster

Re: Treeview + Small Probs

 
0
  #3
Jun 14th, 2009
No no actually sir i didnt want dat, i m able to solve it.....Can u tell me how to attach here the screenshots..so dat it will be helpfull for others..cz i m newbie to this site..
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 234
Reputation: GeekByChoiCe is on a distinguished road 
Solved Threads: 42
GeekByChoiCe GeekByChoiCe is online now Online
Posting Whiz in Training

Re: Treeview + Small Probs

 
0
  #4
Jun 14th, 2009
If i understood your problem right then this would be the solution

  1. Private Sub TreeViewCategories_NodeMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeNodeMouseClickEventArgs) Handles TreeViewCategories.NodeMouseClick
  2. If e.Button = Windows.Forms.MouseButtons.Right Then
  3. TreeViewCategories.SelectedNode = e.Node
  4. ContextMnuTreeview.Show(TreeViewCategories, e.X, e.Y)
  5. End If
  6. End Sub

You might raise the TreeViewCategories.NodeMouseClick event to get the current node.
Last edited by GeekByChoiCe; Jun 14th, 2009 at 3:42 am.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 33
Reputation: ritu verma is an unknown quantity at this point 
Solved Threads: 1
ritu verma ritu verma is offline Offline
Light Poster

Re: Treeview + Small Probs

 
0
  #5
Jun 14th, 2009
Suppose i Add a new node,now want that the new node added automatically comes in EDIT MODE...How to do dat can somebody tell me???
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 33
Reputation: ritu verma is an unknown quantity at this point 
Solved Threads: 1
ritu verma ritu verma is offline Offline
Light Poster

Re: Treeview + Small Probs

 
0
  #6
Jun 14th, 2009
i m able to solved it-
  1. Private Sub ContextMnuAddColl_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ContextMnuAddColl.Click
  2. Try
  3. Dim tnNew As New TreeNode
  4. Dim tnSelected As TreeNode
  5. tnSelected = TreeViewCategories.SelectedNode
  6. If Not tnSelected Is Nothing Then
  7. tnNew = tnSelected.Nodes.Add("New Collection")
  8. tnNew.EnsureVisible()
  9. tnNew.BeginEdit()
  10. End If
  11. TreeViewCategories.ExpandAll()
  12. Catch ex As Exception
  13. MsgBox(ex.Message)
  14. End Try
  15. End Sub

Thx for the help
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC