How to disable tree list rows to be selected in devexpress

1.4k Views Asked by At

I have created a tree list for showing the sector and blocks of memory, now I need to disable the selection of root node and also need to disable the rows of blocks which are already occupied, so that only enable rows can be selected from the tree list.

Also the disabled rows text are little bit lighter for the user to differentiate.

Here I am attaching a sample image for the reference, what I need to achieve

enter image description here

1

There are 1 best solutions below

2
Marko Juvančič On

Have you considered using TreeList.ShowingEditor event? Something like this:

void mytreelist_ShowingEditor(object sender, CancelEventArgs e) {  
   if(mytreelist.FocusedNode.Level == 0 /* root */ || SomeOtherCriteria()) 
   {
      e.Cancel = true;  
   }  
 }

You can handle TreeList.CustomDrawNodeCell to make a row appear disabled:

private void mytreelist_CustomDrawNodeCell(object sender, CustomDrawNodeCellEventArgs e) {
    if(e.Node.Level == 0 /* root */ || SomeOtherCriteria()) 
    {
      e.Appearance.ForeColor = Color.Gray;
    }  
}