ColumnView.ShownEditor Event
Fires immediately after a cell editor is invoked.
Namespace: DevExpress.XtraGrid.Views.Base
Assembly: DevExpress.XtraGrid.v24.1.dll
NuGet Packages: DevExpress.Win.Grid, DevExpress.Win.Navigation
Declaration
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.
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);
}
}
}
Related GitHub Examples
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.