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?

Était-ce utile?

La 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;
  }
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top