I am trying to get the value of a clicked node. I am using the NodeMouseClick event but e.Node and e.Node.Tag are always empty regardless of what Node I click.
Below is an example of how I am populating the control:
String col1 = "All Parent";
String col2 = "Parent";
String col3 = "All";
TreeModel mmodel = new TreeModel();
treeViewAdv1.UseColumns = true;
TreeColumn nodeControl11 = new TreeColumn("Text", 100);
TreeColumn nodeControl21 = new TreeColumn("Text", 200);
TreeColumn nodeControl31 = new TreeColumn("Text", 150);
treeViewAdv1.Model = mmodel;
treeViewAdv1.Columns.Add(nodeControl11);
treeViewAdv1.Columns.Add(nodeControl21);
treeViewAdv1.Columns.Add(nodeControl31);
NodeTextBox ntb = new NodeTextBox();
ntb.DataPropertyName = "NodeControl1";
ntb.ParentColumn = nodeControl11;
NodeTextBox ntb1 = new NodeTextBox();
ntb1.DataPropertyName = "NodeControl2";
ntb1.ParentColumn = nodeControl21;
NodeTextBox ntb2 = new NodeTextBox();
ntb2.DataPropertyName = "NodeControl3";
ntb2.ParentColumn = nodeControl31;
treeViewAdv1.NodeControls.Add(ntb);
treeViewAdv1.NodeControls.Add(ntb1);
treeViewAdv1.NodeControls.Add(ntb2);
treeViewAdv1.BeginUpdate();
for (int i = 0; i <= 20; i++)
{
Node parentnode = new ColumnNode(col1, col2, col3);
mmodel.Nodes.Add(parentnode);
for (int j = 0; j <= 2; j++)
{
Node childnode = new ColumnNode(col1, col2, col3);
parentnode.Nodes.Add(childnode);
}
}
treeViewAdv1.EndUpdate();
I found a solution that works for me. Just set the base.Text to the value you want in the ColumnNode class then you get the row data when using NodeMouseClick.
private class ColumnNode: Node
{
public string NodeControl1=""; // This sould make the DataPropertyName specified in the Node Collection.
public string NodeControl2 = "";
public string NodeControl3 = "";
public ColumnNode(string nodeControl1, string nodeControl2, string nodeControl3)
{
NodeControl1 = nodeControl1;
NodeControl2 = nodeControl2;
NodeControl3 = nodeControl3;
base.Text = NodeControl1 + "\t" + NodeControl2 + "\t" + NodeControl3;
}
}
You also have to use the DataPropertyName = "Text" to retrieve it.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I am trying to get the value of a clicked node. I am using the NodeMouseClick event but e.Node and e.Node.Tag are always empty regardless of what Node I click.
Below is an example of how I am populating the control:
And here is the event which I am using:
Does anyone know how I can make this return the node value?
Many thanks
Mark Fleet
Hi Mark
I found a solution that works for me. Just set the base.Text to the value you want in the ColumnNode class then you get the row data when using NodeMouseClick.
You also have to use the DataPropertyName = "Text" to retrieve it.