private void LoadTree() { TreeNode oNode; oNode = treeView1.Nodes.Add("Customers"); oNode.Tag = "0.customers"; oNode = treeView1.Nodes.Add("Accounts"); oNode.Tag = "0.accounts"; oNode.Expand(); foreach (csItem oItem in csAppStartup.oItems.colItems) { oNode.Nodes.Add(oItem.sCaption); oNode.Tag = "1." + oItem.sItemCode; } }Then in the Mouse up I want to read the tag of the selected node to see which item the user right-clicked on:
private void treeView1_MouseUp(object sender, MouseEventArgs e) { if(e.Button == MouseButtons.Right) { TreeNode oNode = treeView1.SelectedNode; string sNodeInfo = oNode.Tag.ToString(); } }On the last line I'm getting "Object reference not set to an instance of an object.".