你有一个多列listview控件,其中一列是复选框吗?将非常感谢示例代码或链接.
我正在使用visual studio 2005
更好地使用网格视图控件,但如果您只想要一个带有复选框的列,并且该列是您可以写的第一列:
this.listView1.CheckBoxes = true;
Allan Anderson创建了一个自定义控件来让你这样做.您可以在这里找到它:http://www.codeproject.com/KB/list/aa_listview.aspx
以下是该控件的一些示例代码:
GlacialList mylist = new GlacialList(); mylist.Columns.Add( "Column1", 100 ); // this can also be added // through the design time support mylist.Columns.Add( "Column2", 100 ); mylist.Columns.Add( "Column3", 100 ); mylist.Columns.Add( "Column4", 100 ); GLItem item; item = this.glacialList1.Items.Add( "Atlanta Braves" ); item.SubItems[1].Text = "8v"; item.SubItems[2].Text = "Live"; item.SubItems[2].BackColor = Color.Bisque; item.SubItems[3].Text = "MLB.TV"; item = this.glacialList1.Items.Add( "Florida Marlins" ); item.SubItems[1].Text = ""; item.SubItems[2].Text = "Delayed"; item.SubItems[2].BackColor = Color.LightCoral; item.SubItems[3].Text = "Audio"; item.SubItems[1].BackColor = Color.Aqua; // set the background // of this particular subitem ONLY item.UserObject = myownuserobjecttype; // set a private user object item.Selected = true; // set this item to selected state item.SubItems[1].Span = 2; // set this sub item to span 2 spaces ArrayList selectedItems = mylist.SelectedItems; // get list of selected items
像下面一样添加Checkbox列.
myListView.CheckBoxes = true; myListView.Columns.Add(text, width, alignment);
添加ListViewItem如下所示.
ListViewItem lstViewItem = new ListViewItem(); lstViewItem.SubItems.Add("Testing.."); lstViewItem.SubItems.Add("Testing1.."); myListView.Items.Add(lstViewItem);