KB Article A122
Visible to All Users

How to filter or use different choices for each combo box cell in the Grid

Description:
How do I dynamically assign values to the combo box inplace editor based on another column value?

Answer:
Applies to:
XtraGrid, XtraTreeList, XtraVerticalGrid
You should handle the GridView.ShownEditor event, obtain the current in-place editor via the ActiveEditor property, typecast it to ComboBoxEdit and populate its Items property with the desired elements depending on the GridView.FocusedRowHandle value.

C#
using DevExpress.XtraEditors; using DevExpress.XtraGrid.Views.Grid; Hashtable units = new Hashtable(); private void gridView1_ShownEditor(object sender, System.EventArgs e) { GridView view = sender as GridView; if(view.FocusedColumn.FieldName == "Unit") { ComboBoxEdit edit = (ComboBoxEdit)view.ActiveEditor; edit.Properties.Items.Clear(); object parameter = view.GetRowCellValue(view.FocusedRowHandle, "Parameter"); if(units[parameter] != null) edit.Properties.Items.AddRange((ICollection)units[parameter]); } }
Visual Basic
Imports DevExpress.XtraEditors Imports DevExpress.XtraGrid.Views.Grid Dim units As New Hashtable Private Sub GridView1_ShownEditor(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.ShownEditor Dim view As GridView = CType(sender, GridView) If view.FocusedColumn.FieldName = "Unit" Then Dim edit As ComboBoxEdit = CType(view.ActiveEditor, ComboBoxEdit) edit.Properties.Items.Clear() Dim parameter As Object = view.GetRowCellValue(view.FocusedRowHandle, "Parameter") If Not units(parameter) Is Nothing Then edit.Properties.Items.AddRange(CType(units(parameter), ICollection)) End If End If End Sub

See also:
DevExpress WinForms Cheat Sheet - Filter DevExpress Data-Aware Controls
How to show different editors in the same column
How to filter a second LookUp column based on a first LookUp column's value
Assigning Editors to Individual Cells
GridView.CustomRowCellEditForEditing Event

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.