如何在WinListView中使用checkBox

作者:控件中国网   出处:控件中国网   2015-07-30 14:53:05   阅读:10

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 );
        }
}

Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat