Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Trust the Universe
  • *Gurus*
Posted
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.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted

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:

Trust the Universe
Posted

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.

Posted

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

Trust the Universe
Posted

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...

:-)

Posted

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:

Trust the Universe
Posted

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

Posted

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

Trust the Universe
Posted (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 by ballisticnylon

"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

Posted

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:)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...