C# 列表视图控件中的复选框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/60683/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 10:19:25  来源:igfitidea点击:

Checkbox in listview control

提问by leora

Can you have a multicolumn listview control where one of the columns is a checkbox? Example code or links would be greatly appreciated.

你能有一个多列列表视图控件,其中一列是一个复选框吗?示例代码或链接将不胜感激。

I am using visual studio 2005

我正在使用 Visual Studio 2005

采纳答案by Winter

Allan Anderson created a custom control to let you do this. You can find it here: http://www.codeproject.com/KB/list/aa_listview.aspx

Allan Anderson 创建了一个自定义控件来让您执行此操作。你可以在这里找到它:http: //www.codeproject.com/KB/list/aa_listview.aspx

Here's some example code for that control:

这是该控件的一些示例代码:


    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

回答by Nick

回答by Keith

You could use a grid view instead, as that gives you more fine control of column contents.

您可以改用网格视图,因为这样可以更精细地控制列内容。

回答by idursun

You can try TreeViewAdv. It is open source and hosted on sourceforge.

你可以试试TreeViewAdv。它是开源的并托管在 sourceforge 上。

回答by Makis Arvanitis

Better use grid view control, but if you want onlyone column with checkboxes and that column is the firstone you can just write:

更好地使用网格视图控件,但如果您想要一列带有复选框并且该列是第一列,您可以只写:

this.listView1.CheckBoxes = true;

回答by CharithJ

Add Checkbox column like below.

添加复选框列,如下所示。

myListView.CheckBoxes = true;
myListView.Columns.Add(text, width, alignment);

Add ListViewItem s like below.

添加 ListViewItem ,如下所示。

ListViewItem lstViewItem = new ListViewItem();
lstViewItem.SubItems.Add("Testing..");
lstViewItem.SubItems.Add("Testing1..");

myListView.Items.Add(lstViewItem);

回答by chatcja

Why dont you try for XPTable by Mathew Hall

为什么不试试Mathew Hall 的 XPTable

回答by Sohaib Afzal

You can set the the CheckBoxesproperty to true. In code this can be done like this:

您可以将该CheckBoxes属性设置为true. 在代码中,这可以像这样完成:

listView1.CheckBoxes = true;