Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get an Object from a TreeView node in C#

Tags:

c#

treeview

I'm writing an AutoCAD Plug-in that shows all the entities as Nodes in a TreeView. I want to be able to get the object from the Node to be able to work with programmatically. This is my code for when a node is clicked:

private void treeView1_MouseClick(object sender, MouseEventArgs e)
    {
        TreeNode node = treeView1.SelectedNode;
        propertyGrid1.SelectedObject = node;
        /*Entity selectedEntity = node.getObject() as Entity; Pseudo-code, need to know how to do this*/
    }
like image 777
Nick Gilbert Avatar asked Mar 10 '26 01:03

Nick Gilbert


1 Answers

TreeNode has a Tag property that's designed to allow you to associate an object with a Node.

like image 62
Alex K. Avatar answered Mar 11 '26 16:03

Alex K.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!