windowsforms-devexpress-dot-xtragrid-dot-views-dot-grid-dot-gridview-d00d7ac6.md
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
[DXCategory("Editor")]
public event ShowingPopupEditFormEventHandler ShowingPopupEditForm
<DXCategory("Editor")>
Public Event ShowingPopupEditForm As ShowingPopupEditFormEventHandler
The ShowingPopupEditForm event's data class is DevExpress.XtraGrid.Views.Grid.ShowingPopupEditFormEventArgs.
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.
The code below handles the GridView.ShowingPopupEditForm to do the following:
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);
}
}
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