Beginner and trying to get the tag value of a treeview.selectednod

  • Thread starter Thread starter KCBTDev
  • Start date Start date
K

KCBTDev

I am trying to do this line of code:
txtBxMessageBody.Text = ".\\ " + treeView1.SelectedNode.Tag.ToString();

I am getting an error back. It is something pretty simple but I can't
figure it out.
The error is: System.NullReferenceException: Object reference not set to an
instance of an object at myMethod

This is the only line of code in the method and when I only add a string to
the .Text value it runs fine.

Any ideas?
 
either the tree view do not has a node selected (treeView1.SelectedNode ==
null)
or the tag property is not set (treeView1.SelectedNode.Tag == null)
 
Back
Top