Which way I can forbid editing node labels in TreeView if I want some labels be able to be edited and others no?

StackOverflow https://stackoverflow.com/questions/22127366

Question

I set LabelEdit to true and all labels becomes editable. How I can forbid editing level 0 nodes?

Was it helpful?

Solution

Assuming WinForms, try canceling the edit in the BeforeLabelEdit event:

public Form1() {
  InitializeComponent();
  treeView1.BeforeLabelEdit += treeView1_BeforeLabelEdit;
}

void treeView1_BeforeLabelEdit(object sender, NodeLabelEditEventArgs e) {
  if (e.Node.Level == 0) {
    e.CancelEdit = true;
  }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top