Home Forums WinForms controls Other WinForms controls Add value to TreeView Node

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #18360 |

    Hi,

    I’m using the TreeView (latest release) and I’m binding data from dbs as follows:

    DataTable dt = new DataTable();
    dt = GetAllBranchesDT();

    string name = string.Empty;

    Node node = nodeToFill;
    Node dummyNode = null;

    nodeToFill.Items.Clear();

    foreach (System.Data.DataRow dr in dt.Rows)
    {
    name = dr[1].ToString();
    node = new Node(name);

    node.UseMnemonic = false;
    node.Expanded = false;

    node.ExpandedChanging += new System.ComponentModel.CancelEventHandler(this.node_ExpandedChangingOpenBranch);

    dummyNode = new Node(“”);
    dummyNode.Tag = DummyNodeTag;

    node.Items.Add(dummyNode);
    nodeToFill.Items.Add(node);
    }

    The DataTable (dt) contains a column “UserName” and a column “UserID”, in the above example I create the new node with the Text value on the smartItem as the UserName.

    My Question is, I also want to bind the value of the UserID to the node, so that when a node that displays the UserName is clicked it passes the value of the UserID for that node to another function (eg to pull from database another query based on the UserID).
    Can anyone give any pointers to how this is possible?

    Many thanks

    Ric

    Imported from legacy forums. Posted by ric (had 2858 views)

    Xceed Support
    Member
    Post count: 5658

    You could simply use the Tag of your node as the container for the “UserID” value. After, each time you select a Node, you can pass the Tag value with the other function.

    e.g.,
    <code>
    string name = string.Empty;

    nodeToFill.Tag = 0;
    Node node = nodeToFill;

    nodeToFill.Items.Clear();

    foreach( System.Data.DataRow dr in dt.Rows )
    {
    name = dr[ 1 ].ToString();
    node = new Node( name );

    node.UseMnemonic = false;
    node.Expanded = false;

    //Add the “UserID” to the Tag of the Node
    node.Tag = dr[0];

    nodeToFill.Items.Add( node );
    }
    </code>

    Imported from legacy forums. Posted by CharlesB (had 3677 views)

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.