Back to Devexpress

ColumnView.ShownEditor Event

windowsforms-devexpress-dot-xtragrid-dot-views-dot-base-dot-columnview-4bc4a3f7.md

latest8.7 KB
Original Source

ColumnView.ShownEditor Event

Fires immediately after a cell editor is invoked.

Namespace : DevExpress.XtraGrid.Views.Base

Assembly : DevExpress.XtraGrid.v25.2.dll

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

Declaration

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

Event Data

The ShownEditor event's data class is EventArgs.

Remarks

Handle the ShownEditor to perform required actions when a cell editor opens. The ColumnView.ActiveEditor and ColumnView.EditingValue event parameters allow you to identify this editor and its current value.

You can perform additional actions when an editor closes. To do that, handle the ColumnView.HiddenEditor event.

Example

Assume that a Data Grid contains two columns that should allow an end-user to select countries and cities from dropdown lists. When a certain country is selected in the first column, the second column’s dropdown list should only provide cities from the selected country. To display the only appropriate values, the second column’s values should be filtered based on the first column’s value.

This task can be easily implemented if the second column’s in-place editor is a look-up editor (LookUpEditBase descendant).

Handle the ColumnView.ShownEditor event, which fires after an in-place editor has been activated in any grid cell. Use this event to filter the list of items to be displayed in the look-up editor’s dropdown and assign this list to the editor’s RepositoryItemLookUpEditBase.DataSource property.

View Example

csharp
using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Views.Base;
using System;
using System.Collections.Generic;
using System.Linq;

namespace DxSample {
    public partial class MainForm : XtraForm {
        public MainForm() {
            InitializeComponent();
        }

        private void MainForm_Load(object sender, EventArgs e) {
            this.PhonesSource.DataSource = DataContext.GetPhones();
            this.CountriesSource.DataSource = DataContext.GetCountries();
            this.CitiesSource.DataSource = DataContext.GetAllCities();
        }

        private void GridView_ShownEditor(object sender, EventArgs e) {
            ColumnView view = (ColumnView)sender;
            if (view.FocusedColumn.FieldName == "CityCode") {
                LookUpEdit editor = (LookUpEdit)view.ActiveEditor;
                string countryCode = Convert.ToString(view.GetFocusedRowCellValue("CountryCode"));
                editor.Properties.DataSource = DataContext.GetCitiesByCountryCode(countryCode);
            }
        }

        // In certain scenarios you may want to clear the secondary editor's value
        // You can use the RepositoryItem.EditValueChanged event for this purpose
        private void CountryEditor_EditValueChanged(object sender, EventArgs e) {
            this.GridView.PostEditor();
            this.GridView.SetFocusedRowCellValue("CityCode", null);
        }
    }
}
vb
Imports DevExpress.XtraEditors
Imports DevExpress.XtraGrid.Views.Base
Imports System
Imports System.Collections.Generic
Imports System.Linq

Namespace DxSample
    Partial Public Class MainForm
        Inherits XtraForm

        Public Sub New()
            InitializeComponent()
        End Sub

        Private Sub MainForm_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
            Me.PhonesSource.DataSource = DataContext.GetPhones()
            Me.CountriesSource.DataSource = DataContext.GetCountries()
            Me.CitiesSource.DataSource = DataContext.GetAllCities()
        End Sub

        Private Sub GridView_ShownEditor(ByVal sender As Object, ByVal e As EventArgs) Handles GridView.ShownEditor
            Dim view As ColumnView = DirectCast(sender, ColumnView)
            If view.FocusedColumn.FieldName = "CityCode" Then
                Dim editor As LookUpEdit = CType(view.ActiveEditor, LookUpEdit)
                Dim countryCode As String = Convert.ToString(view.GetFocusedRowCellValue("CountryCode"))
                editor.Properties.DataSource = DataContext.GetCitiesByCountryCode(countryCode)
            End If
        End Sub

        ' In certain scenarios you may want to clear the secondary editor's value
        ' You can use the RepositoryItem.EditValueChanged event for this purpose
        Private Sub CountryEditor_EditValueChanged(ByVal sender As Object, ByVal e As EventArgs) Handles CountryEditor.EditValueChanged
            Me.GridView.PostEditor()
            Me.GridView.SetFocusedRowCellValue("CityCode", Nothing)
        End Sub
    End Class
End Namespace

The following code snippets (auto-collected from DevExpress Examples) contain references to the ShownEditor event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-grid-double-click-row-cell/CS/DoubleClickCell/Form1.cs#L34

csharp
gridView1.DoubleClick -= gridView1_DoubleClick;
gridView1.ShownEditor -= gridView1_ShownEditor;
gridView1.HiddenEditor -= gridView1_HiddenEditor;

winforms-grid-image-slider-cell-editor/CS/WindowsFormsApplication202/ImageSliderHelper.cs#L31

csharp
view.RowHeight = slider.Size.Height;
    view.ShownEditor += view_ShownEditor;
}

winforms-grid-double-click-row-cell/VB/DoubleClickCell/Form1.vb#L35

vb
RemoveHandler gridView1.DoubleClick, AddressOf gridView1_DoubleClick
RemoveHandler gridView1.ShownEditor, AddressOf gridView1_ShownEditor
RemoveHandler gridView1.HiddenEditor, AddressOf gridView1_HiddenEditor

winforms-grid-image-slider-cell-editor/VB/WindowsFormsApplication202/ImageSliderHelper.vb#L35

vb
view.RowHeight = slider.Size.Height
    AddHandler view.ShownEditor, AddressOf view_ShownEditor
End Sub

See Also

ShowingEditor

ShowEditor()

CloseEditor()

HideEditor()

Edit Data. Create Cell Editors. Validate User Input

ColumnView Class

ColumnView Members

DevExpress.XtraGrid.Views.Base Namespace