Get tag name of XML file

Hi there

I have this code:

private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)

How do I get the tag name of the selected node

this is the XML I have

<book>book name</book>

so if I select the "book" node, I want

txtbox1.text to have the value from color tag    and
txtbox2.text to have the value from make tag

 hope this makes sense?

Who is Participating?
käµfm³d 👽Connect With a Mentor Commented:
I think the problem you are going to have is that you are wanting to select sibling nodes based on any given node. Do you know that "color" and "make" will always follow "book"? If so, then you may have nothing to worry about; if not, then you can't guarantee that selecting those specific nodes based on the current "clicked" node.

Given what you have above, the following appears to do what you are seeking. It does, however, work on the assumption that "color" and "make" are the next two nodes following "book" (and in that order).
Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
    If e.Node.Name.ToLower() = "book" Then
        txtPopupText.Text = e.Node.Text
        txtbox1.Text = e.Node.NextNode.Text
        txtbox2.Text = e.Node.NextNode.NextNode.Text
        txtbox1.Text = String.Empty
        txtbox2.Text = String.Empty
        txtPopupText.Text = String.Empty
    End If
End Sub

Open in new window

what you wanted to achieve? What is the relations between book node and color/make nodes?
mousemat24Author Commented:
arundhaj, there is no relations , it could be any tag. so I've loaded the XML and placed it into a treeview control

what I want is if someone clicks on book tag, it should populdate the values out from the color and make and place them into 2 textboxes.

The problem I have is because I want the code in the treeView1_AfterSelect event if I do

txtPopupText.Text = e.Node.Text;

it places the value when you select any nodes, I only want the values to appear if they click on the book node, and when they do click on the book node it should take the values from the color and make and place them into a textfield.

anarki_jimbelConnect With a Mentor Commented:
I think kaufmed's solution is right - I did same (just in case - I have C# version below).

Still I have some feeling that it's not what asker wants. If not - please explain once more...
        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
               if (e.Node.Name.ToLower() == "book"){
                    txtPopupText.Text = e.Node.Text;
                    txtbox1.Text = e.Node.NextNode.Text;
                    txtbox2.Text = e.Node.NextNode.NextNode.Text;                
                    txtbox1.Text = String.Empty;
                    txtbox2.Text = String.Empty;
                    txtPopupText.Text = String.Empty;

Open in new window

käµfm³d 👽Commented:

I've really got to start paying attention to which zone I'm in  ;)

Good catch on the C#  :)
All Courses

From novice to tech pro — start learning today.