PrivateSub Form1_Load(sender AsObject, 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.
AddHandlerMe.ultraComboEditor1.InitializeDataItem, AddressOfMe.ultraComboEditor1_InitializeDataItem
End SubPrivateFunction CreateData() As DataTable
' Create a DataTable.
Dim tbl AsNew 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(NewObject() {1, "Crackers", False})
tbl.Rows.Add(NewObject() {2, "Beef Jerky", True})
tbl.Rows.Add(NewObject() {3, "Strawberry Sherbert", False})
Return tbl
End FunctionPrivateSub ultraComboEditor1_InitializeDataItem(sender AsObject, 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.
IfCBool(view.Row("IsOnSale")) Then
e.ValueListItem.Appearance.BackColor = Color.Gold
EndIfEnd Sub
'宣言
Public Event InitializeDataItem As Infragistics.Win.InitializeDataItemHandler
privatevoid 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( newobject[]{ 1, "Crackers", false } );
tbl.Rows.Add( newobject[]{ 2, "Beef Jerky", true } );
tbl.Rows.Add( newobject[]{ 3, "Strawberry Sherbert", false } );
return tbl;
}
privatevoid 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;
}
'宣言
Public Event InitializeDataItem As Infragistics.Win.InitializeDataItemHandler