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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.

käµfm³d 👽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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
anarki_jimbelSenior DeveloperCommented:
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#  :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.