バージョン

DataMember プロパティ (UltraComboEditor)

コントロールの Items コレクションの格納元となる、データ ソースのデータ メンバーを取得または設定します。
シンタックス
'宣言
 
Public Property DataMember As String
public string DataMember {get; set;}
解説

ValueList プロパティに外部 ValueList が割り当てられ、ValueList がデータ バインディングを対応しない場合は (普通は BindableValueList ではありません)、コントロールをバインドしようとするときに例外が発生されます。この場合は、開発者は BindableValueList の使用または新しい ValueList を作成するのに ValueList プロパティをクリアする必要があります。

使用例
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;
}
参照