Back to Devexpress

GridView.ShowingPopupEditForm Event

windowsforms-devexpress-dot-xtragrid-dot-views-dot-grid-dot-gridview-d00d7ac6.md

latest5.9 KB
Original Source

GridView.ShowingPopupEditForm Event

Occurs when an Edit Form is about to be displayed as a separate modal window.

Namespace : DevExpress.XtraGrid.Views.Grid

Assembly : DevExpress.XtraGrid.v25.2.dll

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

Declaration

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

Event Data

The ShowingPopupEditForm event's data class is DevExpress.XtraGrid.Views.Grid.ShowingPopupEditFormEventArgs.

Remarks

You can respond to an Edit Form opening as a separate modal window by handling the ShowingPopupEditForm event. To get the handle that identifies a grid row for which the Edit Form is about to be displayed, use the RowHandle event argument. The BindableControls property provides access to the collection of editors on the Edit Form that are bound to the underlying data source. The EditForm property returns the XtraForm object representing the Edit Form that is about to be displayed.

Before the ShowingPopupEditForm event, the GridView.EditFormShowing and GridView.EditFormPrepared events fire.

Example

The code below handles the GridView.ShowingPopupEditForm to do the following:

  • Change the background of the text box that corresponds to the “Address” column.
  • Access the labels that display column captions and change their font.
  • Access the form’s Cancel button and subscribe to its Click event.

csharp
using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Localization;
using DevExpress.XtraGrid.Views.Grid;

private void gridView1_ShowingPopupEditForm(object sender, ShowingPopupEditFormEventArgs e) {
    // Paint the Address text box in yellow.
    TextEdit textEditAddress = e.BindableControls["Address"] as TextEdit;
    if(textEditAddress != null) textEditAddress.Properties.Appearance.BackColor = Color.LightYellow;

    //Get the list of the form's labels
    List<LabelControl> labels = new List<LabelControl>();
    FindChildrenByType(e.EditForm, labels);
    //Change labels' font
    foreach (LabelControl label in labels)
        label.Appearance.FontStyleDelta = FontStyle.Bold;

    //Get the list of the form's buttons ('Cancel' and 'Update' buttons)
    List<SimpleButton> buttons = new List<SimpleButton>();
    FindChildrenByType(e.EditForm, buttons);
    //Access the 'Cancel' button and subscribe to its Click event
    foreach(SimpleButton btn in buttons)
        if(btn.Text == GridLocalizer.Active.GetLocalizedString(GridStringId.EditFormCancelButton)) {
            btn.Click += CancelButtonClick; 
        }
}

private void CancelButtonClick(object sender, EventArgs e) {
    //...
    (sender as SimpleButton).Click -= CancelButtonClick;
}

void FindChildrenByType<T>(Control parent, List<T> list) where T:class {
    foreach(Control child in parent.Controls) {
        if (child is T)
            list.Add(child as T);
        if (child.HasChildren)
            FindChildrenByType<T>(child, list);
    }
}
vb
Imports DevExpress.XtraEditors
Imports DevExpress.XtraGrid.Localization
Imports DevExpress.XtraGrid.Views.Grid

Private Sub GridView1_ShowingPopupEditForm(sender As Object, e As ShowingPopupEditFormEventArgs) Handles GridView1.ShowingPopupEditForm
    Dim textEditAddress As TextEdit = TryCast(e.BindableControls("Address"), TextEdit)
    If textEditAddress IsNot Nothing Then textEditAddress.Properties.Appearance.BackColor = Color.LightYellow

    Dim labels As List(Of LabelControl) = New List(Of LabelControl)()
    FindChildrenByType(e.EditForm, labels)

    For Each label As LabelControl In labels
        label.Appearance.FontStyleDelta = FontStyle.Bold
    Next

    Dim buttons As List(Of SimpleButton) = New List(Of SimpleButton)()
    FindChildrenByType(e.EditForm, buttons)

    For Each btn As SimpleButton In buttons
        If btn.Text = GridLocalizer.Active.GetLocalizedString(GridStringId.EditFormCancelButton) Then
            AddHandler btn.Click, AddressOf CancelButtonClick
        End If
    Next
End Sub

Private Sub CancelButtonClick(ByVal sender As Object, ByVal e As EventArgs)
    '...
    RemoveHandler(TryCast(sender, SimpleButton)).Click, AddressOf CancelButtonClick
End Sub

Private Sub FindChildrenByType(Of T As Class)(ByVal parent As Control, ByVal list As List(Of T))
    For Each child As Control In parent.Controls
        If TypeOf child Is T Then list.Add(TryCast(child, T))
        If child.HasChildren Then FindChildrenByType(child, list)
    Next
End Sub

See Also

EditFormShowing

EditFormPrepared

EditFormHidden

GridView Class

GridView Members

DevExpress.XtraGrid.Views.Grid Namespace