BaseListBoxControl.DisplayMember Property

Gets or sets the name of the data source field that provides display text for listbox items. This property is not supported when listbox items are rendered based on Item Templates

Namespace: DevExpress.XtraEditors

Assembly: DevExpress.XtraEditors.v20.1.dll

Declaration

[DefaultValue("")]
[DXCategory("Data")]
public virtual string DisplayMember { get; set; }
<DefaultValue("")>
<DXCategory("Data")>
Public Overridable Property DisplayMember As String

Property Value

Type Default Description
String

String.Empty

A string value specifying a field name in a data source.

Remarks

This property is in effect when the ListBox control is bound to a data source with the BaseListBoxControl.DataSource property and listbox items are painted in regular paint mode (Item Templates are not used).

Use the DisplayMember property to specify the field whose values are displayed within the list box control. To get text displayed by a specific list box item, use the BaseListBoxControl.GetItemText method.

Changing the DisplayMember property value at runtime raises the BaseListBoxControl.DisplayMemberChanged event.

Examples

The following sample code declares a ChangeDisplayMember method that accepts two parameters:

  • listBoxControl - a ListBoxControl;
  • memberName - the name of a column already contained within the BaseListBoxControl.DataSource whose contents are to be displayed by ListBoxControl.

Use this method to assign a single column from a table to the DisplayMember property of the ListBoxControl. If the table bound to the control doesn't contain the specified column, method execution will not take effect.

using DevExpress.XtraEditors;
// ...
private void ChangeDisplayMember(ListBoxControl listBoxControl, string memberName){
   DataTable source = listBoxControl.DataSource as DataTable;
   if (source.Columns.Contains(memberName))
      listBoxControl.DisplayMember = memberName;
}

Implements

DevExpress.XtraEditors.ListControls.IDataInfo.DisplayMember
See Also