WinListView是Infragistics Windows Forms里面的一个子控件,主要用于创建数据列表,该控件可以为所有列表元素加入CheckBox,客户可以通过复选框进行选择,具体代码如下:
using Infragistics.Win;
using Infragistics.Win.UltraWinListView;
...
private void Use_Checkboxes_in_WinListView_Load(object sender, EventArgs e)
{
// Use the data from the 'Customers' table in the Northwind database
this.customersTableAdapter.Fill(this.nWindDataSet1.Customers);
// Set the control's View property to 'List'
this.ultraListView1.View = UltraListViewStyle.List;
// For the second control, set MultiColumn to false
this.ultraListView2.View = UltraListViewStyle.List;
this.ultraListView2.ViewSettingsList.MultiColumn = false;
// Set the CheckBoxStyle property to 'CheckBox'
this.ultraListView1.ViewSettingsList.CheckBoxStyle = CheckBoxStyle.CheckBox;
for ( int i = 0; i < this.nWindDataSet1.Customers.Rows.Count; i ++ )
{
DataRow row = this.nWindDataSet1.Customers.Rows[i];
string customerID = row["CustomerID"] as string;
string companyName = row["CompanyName"] as string;
this.ultraListView1.Items.Add( customerID, companyName );
}
}
private void btnGetCheckedItems_Click(object sender, EventArgs e)
{
// List the customers that were checked by the end user
// Clear the previous list
this.ultraListView2.Items.Clear();
// Get a reference to the control's CheckedItems collection
UltraListViewCheckedItemsCollection checkedItems = this.ultraListView1.CheckedItems;
// Iterate the CheckedItems collection and add the company names
// to the second UltraListView control.
for ( int i = 0; i < checkedItems.Count; i ++ )
{
UltraListViewItem checkedItem = checkedItems[i];
this.ultraListView2.Items.Add( checkedItem.Key, checkedItem.Value );
}
}