Version

DataMember Property (UltraComboEditor)

Gets/sets the data member of the data source from which the control's Items collection is populated.
Syntax
'Declaration
 
Public Property DataMember As String
public string DataMember {get; set;}
Remarks

If an external ValueList has already been assigned to the ValueList property and that ValueList does not support data binding (generally not a BindableValueList), an exception will be thrown when trying to bind the control. In this situation, the developer is responsible either for using a BindableValueList or to clear out the ValueList property so that the control will create a new one.

Example
This code sample demonstrates how to use the databinding support offered by the UltraComboEditor.

For an overview of how to handle events in Visual Basic or Visual C#, see Event Handlers in Visual Basic and Visual C#. For specific information and code examples illustrating how to consume events in your application, see Consuming Events in the .NET Framework Developer's Guide.

Private Sub Form1_Load(sender As Object, e As System.EventArgs)
   ' Create a DataTable.
   Dim tbl As DataTable = Me.CreateData()
   
   ' Assign the DataTable as the UltraComboEditor's data source.
   Me.ultraComboEditor1.DataSource = tbl
   
   ' Since the underlying data list is directly on the data source, there
   ' is no need to specify a sub-object to get the data from.  Setting this
   ' property to an empty string is not necessary to do.  If the data source
   ' were a DataSet, instead of a DataTable, then it would be necessary to 
   ' specify the name of the DataTable to retrieve the values from.
   Me.ultraComboEditor1.DataMember = ""
   
   ' NOTE: Instead of setting the DataSource and DataMember properties separately,
   ' it is possible to set them both at once.  Use the SetDataBinding method to
   ' perform both assignments in an atomic operation, like so:
   '
   ' this.ultraComboEditor1.SetDataBinding( tbl, "" );

   ' Indicate that values from the "Name" column should be displayed 
   ' in the dropdown and edit portions of the control.
   Me.ultraComboEditor1.DisplayMember = "Name"
   
   ' Indicate that the UltraComboEditor's Value property should return 
   ' values from the "ID" column.
   Me.ultraComboEditor1.ValueMember = "ID"
   
   ' Attach a handler to the InitializeDataItem event so that when ValueListItems
   ' are created to represent values in the data source, value-specific formatting
   ' will be applied to them.
	AddHandler Me.ultraComboEditor1.InitializeDataItem, AddressOf Me.ultraComboEditor1_InitializeDataItem
  
End Sub


Private Function CreateData() As DataTable
   ' Create a DataTable.
   Dim tbl As New DataTable("FoodItems")
   
   ' Supply schematic information.
   tbl.Columns.Add("ID", GetType(Integer))
   tbl.Columns.Add("Name")
   tbl.Columns.Add("IsOnSale", GetType(Boolean))
   
   ' Supply content.
   tbl.Rows.Add(New Object() {1, "Crackers", False})
   tbl.Rows.Add(New Object() {2, "Beef Jerky", True})
   tbl.Rows.Add(New Object() {3, "Strawberry Sherbert", False})
   
   Return tbl
End Function


Private Sub ultraComboEditor1_InitializeDataItem(sender As Object, e As Infragistics.Win.InitializeDataItemEventArgs)
   ' Obtain a reference to the object in the data source's underlying list
   ' which the new ValueListItem represents.
   Dim view As DataRowView = CType(e.ValueListItem.ListObject, DataRowView)
   
   ' If the food item is on sale, set the ValueListItem's background color to golden.
   If CBool(view.Row("IsOnSale")) Then
      e.ValueListItem.Appearance.BackColor = Color.Gold
   End If
End Sub
private void Form1_Load(object sender, System.EventArgs e)
{
	// Create a DataTable.
	DataTable tbl = this.CreateData();

	// Assign the DataTable as the UltraComboEditor's data source.
	this.ultraComboEditor1.DataSource = tbl;

	// Since the underlying data list is directly on the data source, there
	// is no need to specify a sub-object to get the data from.  Setting this
	// property to an empty string is not necessary to do.  If the data source
	// were a DataSet, instead of a DataTable, then it would be necessary to 
	// specify the name of the DataTable to retrieve the values from.
	this.ultraComboEditor1.DataMember = "";
	
	// NOTE: Instead of setting the DataSource and DataMember properties separately,
	// it is possible to set them both at once.  Use the SetDataBinding method to
	// perform both assignments in an atomic operation, like so:
	//
	// this.ultraComboEditor1.SetDataBinding( tbl, "" );

	// Indicate that values from the "Name" column should be displayed 
	// in the dropdown and edit portions of the control.
	this.ultraComboEditor1.DisplayMember = "Name";

	// Indicate that the UltraComboEditor's Value property should return 
	// values from the "ID" column.
	this.ultraComboEditor1.ValueMember = "ID";

	// Attach a handler to the InitializeDataItem event so that when ValueListItems
	// are created to represent values in the data source, value-specific formatting
	// will be applied to them.
	this.ultraComboEditor1.InitializeDataItem += 
		new Infragistics.Win.InitializeDataItemHandler( this.ultraComboEditor1_InitializeDataItem );
}

private DataTable CreateData()
{
	// Create a DataTable.
	DataTable tbl = new DataTable( "FoodItems" );

	// Supply schematic information.
	tbl.Columns.Add( "ID", typeof(int) );
	tbl.Columns.Add( "Name" );
	tbl.Columns.Add( "IsOnSale", typeof(bool) );

	// Supply content.
	tbl.Rows.Add( new object[]{ 1, "Crackers", false } );
	tbl.Rows.Add( new object[]{ 2, "Beef Jerky", true } );
	tbl.Rows.Add( new object[]{ 3, "Strawberry Sherbert", false } );

	return tbl;
}

private void ultraComboEditor1_InitializeDataItem( object sender, Infragistics.Win.InitializeDataItemEventArgs e )
{
	// Obtain a reference to the object in the data source's underlying list
	// which the new ValueListItem represents.
	DataRowView view = e.ValueListItem.ListObject as DataRowView;

	// If the food item is on sale, set the ValueListItem's background color to golden.
	if( view != null && (bool)view.Row["IsOnSale"] )
		e.ValueListItem.Appearance.BackColor = Color.Gold;
}
Requirements

Target Platforms: Windows 10, Windows 8.1, Windows 8, Windows 7, Windows Server 2012, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also