Other DevExpress WinForms Cheat Sheets
The DevExpress WinForms suite includes over 80 editors (see this help article for the complete list: Included Controls and Components). ComboBox-like editors (item selectors) allow users to select a value from a predefined list. In certain scenarios, it's necessary to display a value different that stored internally (e.g. an editor stores item IDs, but displays human-friendly record descriptions to users). ComboBoxEdit shows a static list of items and is not suitable for this task. Instead, use ImageComboBoxEdit or Lookup Editors.
- ImageComboBoxEdit operates in unbound mode and shows static data.
- Lookup Editors are suitable for data from a bound data source.
Like any editor, these components can be used both in standalone and in-place modes.
In TextEdit-based editors (SpinEdit, DateEdit, ButtonEdit, etc.) and data-aware controls (Data Grid, Tree List, etc.) you can use Custom Formatting to display the value different from a real value in both display and edit modes. To do this, create a new Custom Formatter which encapsulates custom formatting logic and assign it to the DisplayFormat (RepositoryItem.DisplayFormat, GridColumn.DisplayFormat, etc.) and/or EditFormat (RepositoryItem.EditFormat, etc.) properties.
Note that some editors (DateEdit, TimeEdit, CalcEdit and others) use have default Input Masks that limit the input to valid values only. EditFormat formats the editor's value only when the editor's MaskProperties.MaskType property is set to MaskType.None, MaskType.RegEx, MaskType.Regular or MaskType.Simple.
DevExpress data-aware controls (Gantt Control, Data Grid, Tree List, Vertical Grid, etc.) also offer several other ways to display custom values:
-
The ~CustomDisplayText (GridView.CustomColumnDisplayText / PivotGridControl.CustomCellDisplayText, etc.) or ~CustomDrawCell (GridView.CustomDrawCell / TreeList.CustomDrawNodeCell, etc.) events. Assign a required display value to the e.DisplayText parameter.
-
Unbound Columns (GridView: Unbound Columns / PivotGrid: Unbound Fields / Vertical Grid: Unbound Rows). You can hide an original column and add a new Unbound Column instead. Handle the ~CustomUnboundData (GridView: CustomUnboundColumnData / PivotGridControl.CustomUnboundFieldData, etc.) event to supply unbound columns with required values. You can access real values using the Row parameter - cast it to a required data type and access a required property value. Refer to this Cheat Sheet to learn more about Unbound Columns: DevExpress WinForms Cheat Sheet - Show Values from External Sources and Use Formulas and Expressions to Calculate Field Values.
Examples
My ComboBox is bound to Int type data. Can it display strings in the UI?
ComboBoxEdit does not support separate values and display texts. This functionality is supported by ImageComboBoxEdit. However, if your lookup data (value and display text pairs) is stored in a data source, it is better to use one of our Lookup Editors.
Can I replace values this ComboBox shows?
ComboBoxEdit cannot show strings that differ from internally stored values. We recommend using ImageComboBoxEdit to show a list of static values, or Lookup Editors to show values from a data source.
Data Grid Column bound to one field. Can I replace its cell values with values of another field?
Lookup Editors allow you to replace an actual data source value with another value or text. For more information about how to assign a look-up editor to the Grid's column, see this help topic: How to: Create Lookup Editor and Bind It to Data Source. You can learn how to work with in-place editors in the Grid here: Cell Values, Editors, and Validation.