Version

ValueMember Property (UltraOptionSet)

Gets/sets the name of the property in the data source from which to retrieve the values associated with items in the dropdown.
Syntax
'Declaration
 
Public Property ValueMember As String
public string ValueMember {get; set;}
Remarks

To specify that the value of the control should return the entire ListObject of the item, instead of any individual field on that item, set ValueMember to Infragistics.Win.BindableValueList.USE_LISTOBJECT_AS_VALUEMEMBER

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

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 UltraOptionSet's data source.
   Me.ultraOptionSet1.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.ultraOptionSet1.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.ultraOptionSet1.SetDataBinding( tbl, "" );
   ' Indicate that values from the "Name" column should be displayed 
   ' in the dropdown and edit portions of the control.
   Me.ultraOptionSet1.DisplayMember = "Name"
   
   ' Indicate that the UltraOptionSet's Value property should return 
   ' values from the "ID" column.
   Me.ultraOptionSet1.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.ultraOptionSet1.InitializeDataItem, AddressOf Me.ultraOptionSet1_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 ultraOptionSet1_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 UltraOptionSet's data source.
	this.ultraOptionSet1.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.ultraOptionSet1.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.ultraOptionSet1.SetDataBinding( tbl, "" );

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

	// Indicate that the UltraOptionSet's Value property should return 
	// values from the "ID" column.
	this.ultraOptionSet1.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.ultraOptionSet1.InitializeDataItem += 
		new Infragistics.Win.InitializeDataItemHandler( this.ultraOptionSet1_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 ultraOptionSet1_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