You are asking about selection of the node, but by description of the behavior it looks like you need to handle selection of the node itself.
First of all, put some relevant data in each node to use while processing event.
internal struct TreeNodeData {
internal TreeNodeData(string name, string description) { fName = name; fDescription = description; }
internal string Name { return fName; }
internal string Description { return fDescription; }
string fName, fDescription;
}
Add the items of this type to your tree view, add more relevant data (command, as you say). I would suggest you add a delegate instance which will run execute the command.
You should assign an instance of this structure to the property
Tag
of each node you want to process.
Now, I don't think you need a click to show description. The description should be shown on selection. Set it up like this:
myTreeView.AfterSelect += (sender, eventArgs) => {
if (eventArgs.Node.Tag == null) return;
TreeNodeData nodeData = (TreeNodeData)eventArgs.Node.Tag;
ProcessTreeViewNodeSelection(nodeData);
}
myTreeView.NodeMouseDoubleClick += (sender, eventArgs) => {
TreeViewNode selectedNode = eventArgs.Node;
if (selectedNode.Tag == null) return;
TreeNodeData nodeData = (TreeNodeData)selectedNode.Tag;
RunTreeViewCommand(nodeData);
}
void ProcessTreeViewNodeSelection(TreeNodeData nodeData) {
textBoxNodeDescription.Text = nodeData.Description;
}
void RunTreeViewCommand(TreeNodeData nodeData) {
}
Both event handlers shown above should be added (+=) before the form is shown. I usually call the code adding handlers in the constructors after
InitializeComponent
.
Is it clear now?
Good luck,
—SA