feurich Posted November 12, 2003 Posted November 12, 2003 Is there a way to differentiate between a click on a parent node and a click on a child node. I need it because i'm trying to make the treeview afterselect event react different on the both clicks. I'm using the afterselect event. Thanks in advance. Cire :D Quote Trust the Universe
*Gurus* divil Posted November 12, 2003 *Gurus* Posted November 12, 2003 As one of the arguments to the procedure handling the event, you are passed the node that was selected. You can use your own logic on this to determine what to do with it. Bear in mind that a node can be a parent _and_ a child, so this may not be as simple as it first appears. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
feurich Posted November 12, 2003 Author Posted November 12, 2003 One level My treeview only has parent nodes and one level of child nodes. So i thought If a node has more then zero as a nodecount then it has to be a parent node. Because in my situation child nodes have no nodes. Is this correct or am I doing something wrong? :rolleyes: Quote Trust the Universe
tate Posted November 12, 2003 Posted November 12, 2003 What is a treeview? Please add some more detail to your question. A click event of numerous types is associated with the child or parent form in which it took place. Quote
feurich Posted November 12, 2003 Author Posted November 12, 2003 A treeview is a When i say treeview I mean a treeview Control. The event I try to use is the afterSelect event. I'm trying to make a program react different when clicking on a parent node then when I click on a subnode(Childnode). I don't know what I need to explain more. Cire Quote Trust the Universe
No-one Posted November 12, 2003 Posted November 12, 2003 Try setting a treeview control up on the form. add a few parents and a few children using the property editor in the IDE. Then to determine the dependancies try this... Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect If Not (e.Node.Parent Is Nothing) Then If (e.Node.GetNodeCount(True) > 0) Then MessageBox.Show(" i am a parent and a child") Exit Sub End If MessageBox.Show("I am a child") Else MessageBox.Show("I am a parent") End If End Sub change to suit your needs... :-) Quote
feurich Posted November 18, 2003 Author Posted November 18, 2003 It works Thanks for the very clear code. I just need to understand the e parameter in the argument list of the event ?? Cire:confused: Quote Trust the Universe
Voca Posted November 18, 2003 Posted November 18, 2003 As far as I did understand the e's in all events are a Collection of properties/options/methods, quite special to your event. You do not need to pass this to your app yourself. All necessary arguments are passed from Windows. Voca Quote
feurich Posted November 18, 2003 Author Posted November 18, 2003 Is there info on it Do you also know if there is information on the internet on it ? I have read 4 books on .Net but in non of them the e's (please give me a for them) are explained. Cire Quote Trust the Universe
ballisticnylon Posted November 18, 2003 Posted November 18, 2003 (edited) Here's a Function that you can pass a treenode, that returns it's depth in the treeview's heirarchy. Private Function NodeDepth(ByVal node As TreeNode) As Integer ' Determine the number of layers down in the TreeView's hierarchy ' that the passed TreeNode has. Return -1 if a 'NullNode' is passed. Dim Depth As Integer Try Do If node.Parent Is Nothing Then Return Depth node = node.Parent Depth += 1 Loop Catch ex As NullReferenceException Return -1 End Try End Function And you'd just use the function like this: Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect Select Case NodeDepth(e.node) Case Is = 0 Messagebox.Show("You clicked on the top level") Case Is = 1 Messagebox.Show("You clicked on the second level") Case Is = 2 Messagebox.Show("You clicked on the third level") Case Is = -1 ' Do nothing, no node was clicked End Select End Sub Edited November 19, 2003 by ballisticnylon Quote "It may be roundly asserted that human ingenuity cannot concoct a cipher which human ingenuity cannot resolve." - Edgar Allan Poe, 1841 I long to accomplish great and noble tasks, but it is my chief duty to accomplish humble tasks as though they were great and noble. The world is moved along, not only by the mighty shoves of its heroes, but also by the aggregate of the tiny pushes of each honest worker. - Helen Keller
Voca Posted November 19, 2003 Posted November 19, 2003 Re: Is there info on it Do you also know if there is information on the internet on it ? I have read 4 books on .Net but in non of them the e's (please give me a for them) are explained. I have also read lots of books an found almost nothing depending on these EventArgs (e's). If you are using VisualStudio you will automatically recieve all the options available to the corresponding e. As I told you in my first posting, the number of these Properties/Methods/Events variies depending on the event you are using. THe only source I know for sure explaining the EventArgs (more or less) is MSDN. Perhaps you try some advanced books on VB.net or C# but I do not think you will find much on this topic. I do not think there ist much Information on the Internet either. Perhaps you surf MSDN or Technet on the Microsoft-Site but I do not think you will find there any information which event triggers which EventArgs. But if you find any Information on this: tell me Voca:) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.