Search code examples
c#devexpressxtratreelist

DevExpress TreeView add fold then highlight and focus row in edit mode


In my treeview, after adding a fold, I want that row to be highlghted and in edit mode. So that user can enter name for new folder. I am able to focus the node but not set the row in edit mode.


Solution

  • Had exactly the same issue, here's the code snips, requires a global variable to distinguish a regular click from an 'I want to edit' click:

    First create a global variable

    bool fChanged = false;
    

    Put this code after you have created your node, this will trigger the editor (make sure you have flagged the grid for editing as well as the columns you want to edit.

    m_treelist.SetFocusedNode (node);
    fChanged = false;
    m_treelist.ShowEditor ();
    

    Add an event to your treelist Click event, add this code

    fChanged = false;
    

    Add an event to your OnFocusedNodeChanged event, add this code

    fChanged = true;
    

    In the ShowingEditor event you want to put this code

    e.Cancel = fChanged;
    

    If you have any actions in mouse clicks (for context menus, make sure to set fChanged to false as this will also trigger the editor.

    Finally all you need to do is handle ValidateEditor and HiddenEditor with your code.

    HTH