Back to Devexpress

PopupBaseEdit.CloseUp Event

windowsforms-devexpress-dot-xtraeditors-dot-popupbaseedit-04f5a57b.md

latest5.4 KB
Original Source

PopupBaseEdit.CloseUp Event

Enables you to specify whether the modifications performed within the editor’s popup window should be accepted by the editor.

Namespace : DevExpress.XtraEditors

Assembly : DevExpress.XtraEditors.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

csharp
[DXCategory("Events")]
public virtual event CloseUpEventHandler CloseUp
vb
<DXCategory("Events")>
Public Overridable Event CloseUp As CloseUpEventHandler

Event Data

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

PropertyDescription
AcceptValueGets or sets a value indicating whether CloseUpEventArgs.Value should be accepted or discarded.
CloseModeGets a value indicating how the popup editor’s dropdown window was closed.
PressedButtonReturns which popup button has been pressed by an end-user.
ValueGets or sets a value to assign to the editor’s edit value.

Remarks

The CloseUp event fires when closing the popup window. It enables you to specify whether modifications performed within the popup window should be accepted by the editor.

The CloseUp event is equivalent to the RepositoryItemPopupBase.CloseUp event available via the editor’s Properties property, i.e. adding/removing an event handler for the current event actually affects the RepositoryItemPopupBase.CloseUp event.

Please refer to the RepositoryItemPopupBase.CloseUp event description for more information.

Example

The following example shows how you can restrict user input in a date editor. The user is able to enter dates between January 1 and December 31 of the current year. Other dates are not acceptable. If the user selects a date less than January 1, the edit value will be set to January 1. If the selected date is greater than December 31, the edit value will be set to the maximum possible date.

For this purpose, we will use the editor’s PopupBaseEdit.CloseUp event. Its handler is listed below.

Note that the user can enter the date in the edit box without activating the dropdown window. In this case, the PopupBaseEdit.CloseUp event is not fired, and therefore, no validation is performed. To prevent such situations, you can set the RepositoryItemButtonEdit.TextEditStyle property to TextEditStyles.DisableTextEditor. Another method is to handle the RepositoryItem.EditValueChanging event, to control edit value changes.

csharp
using DevExpress.XtraEditors.Controls;
private void dateEdit1_CloseUp(object sender, CloseUpEventArgs e) {
    DateTime selectedDate = (DateTime)e.Value;
    int currentYear = DateTime.Today.Year;
    if (selectedDate.Year < currentYear)
      e.Value = new DateTime(currentYear, 1, 1);
    else
      if (selectedDate.Year > currentYear)
        e.Value = new DateTime(currentYear, 12, 31);      
}
vb
Private Sub DateEdit1_CloseUp(ByVal sender As Object, _
  ByVal e As DevExpress.XtraEditors.Controls.CloseUpEventArgs) _
  Handles DateEdit1.CloseUp
    Dim selectedDate As DateTime = CType(e.Value, DateTime)
    Dim currentYear As Integer = DateTime.Today.Year
    If selectedDate.Year < currentYear Then
      e.Value = New DateTime(currentYear, 1, 1)
    ElseIf (selectedDate.Year > currentYear) Then
      e.Value = New DateTime(currentYear, 12, 31)
    End If
End Sub

See Also

CloseUp

RepositoryItemPopupBase.QueryCloseUp

Popup

PopupBaseEdit.QueryCloseUp

EditValueChanging

EditValueChanged

PopupBaseEdit Class

PopupBaseEdit Members

DevExpress.XtraEditors Namespace