Skip to main content
A newer version of this page is available. .

Edit Form

  • 3 minutes to read

Instead of In-place Editors, cell values can be edited in a modal form — Edit Form. To invoke the Edit Form, users can double-click a node, press the Enter or F2 key.

To enable the Edit Form, set the TreeList.OptionsBehavior.EditingMode property to EditForm.

using DevExpress.XtraTreeList;

treeList1.OptionsBehavior.EditingMode = TreeListEditingMode.EditForm;

Options

The TreeList.OptionsEditForm property provides access to the following Edit Form options:

  • BindingMode — Gets or sets whether changes in the Edit Form are immediately applied to cells in the Tree List or only when the user closes the Edit Form.
  • CustomEditFormLayout — Gets or sets a custom Edit Form.
  • EditFormColumnCount — Gets or sets the number of layout columns in the Edit Form.
  • FormCaptionFormat — Gets or sets a custom caption of the EditFrom. You can display cell values in the caption.
  • PopupEditFormWidth — Gets or sets the width of the Edit Form.
  • ShowOnDoubleClick — Gets or sets whether the Edit Form is opened with a double-click.
  • ShowOnEnterKey — Gets or sets whether the Edit Form is opened with the Enter key.
  • ShowOnF2Key — Gets or sets whether the Edit Form is opened with the F2 key.

Show and Hide the Edit Form in Code

Use the following methods to open/close the Edit Form in code:

The EditFormShowing and EditFormPrepared events fire when the Edit Form is about to be displayed. You can cancel the action or customize the Edit Form. The EditFormHidden event fires when the Edit Form is closed.

The code below shows how to prevent the Edit Form from being shown in a particular case, focus an editor in the Edit Form, subscribe to the editor’s events, and get the clicked button when the Edit Form is closed.

using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraTreeList;

// Prevents the Edit Form from being shown depending on the cell data.
private void treeList1_EditFormShowing(object sender, DevExpress.XtraTreeList.EditFormShowingEventArgs e) {
    if (e.Node.GetValue(colCity).Equals("Berlin"))
        e.Allow = false;
}
// Focuses the editor in the Edit Form that corresponds to the column focused in the Tree List.
// Subscribes to an editor's events.
private void treeList1_EditFormPrepared(object sender, DevExpress.XtraTreeList.EditFormPreparedEventArgs e) {
    TreeList treeList = sender as TreeList;
    Control editor = e.BindableControls[treeList.FocusedColumn];
    if (editor != null) {
        editor.Focus();
        ((IContainerControl)e.Panel).ActivateControl(editor);
    }

    TextEdit textEdit = e.BindableControls[colCity] as TextEdit;
    if (textEdit != null)
        textEdit.EditValueChanging += TextEdit_EditValueChanging;
}
private void TextEdit_EditValueChanging(object sender, ChangingEventArgs e) {
    // ...
}
// Unsubscribes from the editor's events.
// Shows a message depending on the clicked button.
private void treeList1_EditFormHidden(object sender, DevExpress.XtraTreeList.EditFormHiddenEventArgs e) {
   TextEdit textEdit = e.BindableControls[colCity] as TextEdit;
    if (textEdit != null)
        textEdit.EditValueChanging -= TextEdit_EditValueChanging;
    if (e.Result == EditFormResult.Update)
        XtraMessageBox.Show("Changes are successfully saved.");

}