Back to Devexpress

TreeList.EditFormShowing Event

windowsforms-devexpress-dot-xtratreelist-dot-treelist-15c4b10e.md

latest9.3 KB
Original Source

TreeList.EditFormShowing Event

Fires when the Edit Form is about to be displayed. Allows you to cancel the action.

Namespace : DevExpress.XtraTreeList

Assembly : DevExpress.XtraTreeList.v25.2.dll

NuGet Packages : DevExpress.Win.Navigation, DevExpress.Win.TreeList

Declaration

csharp
[DXCategory("Editor")]
public event EditFormShowingEventHandler EditFormShowing
vb
<DXCategory("Editor")>
Public Event EditFormShowing As EditFormShowingEventHandler

Event Data

The EditFormShowing event's data class is EditFormShowingEventArgs. The following properties provide information specific to this event:

PropertyDescription
AllowGets or sets whether it is allowed to show the Edit Form.
NodeGets the node for which the Edit Form is about to be shown.

Examples

The control displays a list of booked flights. A user edits flights in the Edit Form. The code below shows how to do the following:

  • disable the Return field if the One Way option is selected

  • set the Return field’s minimum value to the Departure field’s value

  • C#

  • VB.NET

csharp
using DevExpress.XtraEditors;

treeList1.OptionsBehavior.EditingMode = DevExpress.XtraTreeList.TreeListEditingMode.EditForm;
treeList1.EditFormPrepared += TreeList1_EditFormPrepared;
treeList1.EditFormHidden += TreeList1_EditFormHidden;

CheckEdit editOneWay;
DateEdit editDeparture;
DateEdit editReturn;

private void TreeList1_EditFormPrepared(object sender, DevExpress.XtraTreeList.EditFormPreparedEventArgs e) {
    editDeparture = e.BindableControls["Departure"] as DateEdit;
    editReturn = e.BindableControls["Return"] as DateEdit;
    editOneWay = e.BindableControls["One Way"] as CheckEdit;
    if (editOneWay != null)
        editOneWay.EditValueChanging += EditOneWay_EditValueChanging;
    if(editDeparture != null)
        editDeparture.EditValueChanged += EditDeparture_EditValueChanged;
}

private void EditDeparture_EditValueChanged(object sender, EventArgs e) {
    editReturn.Properties.MinValue = (DateTime)editDeparture.EditValue;
}

private void EditOneWay_EditValueChanging(object sender, DevExpress.XtraEditors.Controls.ChangingEventArgs e) {
    if ((bool)e.NewValue)
        editReturn.Enabled = false;
    else
        editReturn.Enabled = true;
}

private void TreeList1_EditFormHidden(object sender, DevExpress.XtraTreeList.EditFormHiddenEventArgs e) {
    if (editOneWay != null)
        editOneWay.EditValueChanging -= EditOneWay_EditValueChanging;
    if(editDeparture != null)
        editDeparture.EditValueChanged -= EditDeparture_EditValueChanged;
    editOneWay = null;
    editDeparture = null;
    editReturn = null;
}
vb
Imports DevExpress.XtraEditors

treeList1.OptionsBehavior.EditingMode = DevExpress.XtraTreeList.TreeListEditingMode.EditForm
AddHandler treeList1.EditFormPrepared, AddressOf TreeList1_EditFormPrepared
AddHandler treeList1.EditFormHidden, AddressOf TreeList1_EditFormHidden

Private editOneWay As CheckEdit
Private editDeparture As DateEdit
Private editReturn As DateEdit

Private Sub TreeList1_EditFormPrepared(ByVal sender As Object, ByVal e As DevExpress.XtraTreeList.EditFormPreparedEventArgs)
    editDeparture = TryCast(e.BindableControls("Departure"), DateEdit)
    editReturn = TryCast(e.BindableControls("Return"), DateEdit)
    editOneWay = TryCast(e.BindableControls("One Way"), CheckEdit)
    If editOneWay IsNot Nothing Then
        AddHandler editOneWay.EditValueChanging, AddressOf EditOneWay_EditValueChanging
    End If
    If editDeparture IsNot Nothing Then
        AddHandler editDeparture.EditValueChanged, AddressOf EditDeparture_EditValueChanged
    End If
End Sub

Private Sub EditDeparture_EditValueChanged(ByVal sender As Object, ByVal e As EventArgs)
    editReturn.Properties.MinValue = DirectCast(editDeparture.EditValue, DateTime)
End Sub

Private Sub EditOneWay_EditValueChanging(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.ChangingEventArgs)
    If DirectCast(e.NewValue, Boolean) Then
        editReturn.Enabled = False
    Else
        editReturn.Enabled = True
    End If
End Sub

Private Sub TreeList1_EditFormHidden(ByVal sender As Object, ByVal e As DevExpress.XtraTreeList.EditFormHiddenEventArgs)
    If editOneWay IsNot Nothing Then
        RemoveHandler editOneWay.EditValueChanging, AddressOf EditOneWay_EditValueChanging
    End If
    If editDeparture IsNot Nothing Then
        RemoveHandler editDeparture.EditValueChanged, AddressOf EditDeparture_EditValueChanged
    End If
    editOneWay = Nothing
    editDeparture = Nothing
    editReturn = Nothing
End Sub

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.

csharp
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.");

}
vb
Imports DevExpress.XtraEditors
Imports DevExpress.XtraEditors.Controls
Imports DevExpress.XtraTreeList

Private Sub treeList1_EditFormShowing(ByVal sender As Object, ByVal e As DevExpress.XtraTreeList.EditFormShowingEventArgs) _
    Handles treeList1.EditFormShowing
    If e.Node.GetValue(colCity).Equals("Berlin") Then
        e.Allow = False
    End If
End Sub
Private Sub treeList1_EditFormPrepared(ByVal sender As Object, ByVal e As DevExpress.XtraTreeList.EditFormPreparedEventArgs) _
    Handles treeList1.EditFormPrepared
    Dim treeList As TreeList = TryCast(sender, TreeList)
    Dim editor As Control = e.BindableControls(treeList.FocusedColumn)
    If editor IsNot Nothing Then
        editor.Focus()
        DirectCast(e.Panel, IContainerControl).ActivateControl(editor)
    End If

    Dim textEdit As TextEdit = TryCast(e.BindableControls(colCity), TextEdit)
    If textEdit IsNot Nothing Then
        AddHandler textEdit.EditValueChanging, AddressOf TextEdit_EditValueChanging
    End If
End Sub
Private Sub TextEdit_EditValueChanging(ByVal sender As Object, ByVal e As ChangingEventArgs)
    ' ...
End Sub
Private Sub treeList1_EditFormHidden(ByVal sender As Object, ByVal e As DevExpress.XtraTreeList.EditFormHiddenEventArgs) _
    Handles treeList1.EditFormHidden
    Dim textEdit As TextEdit = TryCast(e.BindableControls(colCity), TextEdit)
    If textEdit IsNot Nothing Then
        RemoveHandler textEdit.EditValueChanging, AddressOf TextEdit_EditValueChanging
    End If
    If e.Result = EditFormResult.Update Then
        XtraMessageBox.Show("Changes are successfully saved.")
    End If
End Sub

See Also

EditFormPrepared

EditFormHidden

Edit Form

TreeList Class

TreeList Members

DevExpress.XtraTreeList Namespace