listview怎样设置某列为checkbox

fly_Jerry 2006-11-21 03:01:50
比如用listview显示某个表的内容,表中有一项Deleted表示该记录已被删除,希望listview中的某列以checkbox的形式来显示此信息,如:
Name Deleted Sex
张三 [v] 男
李四 [ ] 女

v表示checkbox已选中
...全文
382 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
hq2008 2007-01-27
  • 打赏
  • 举报
回复
g
kui1015 2006-11-21
  • 打赏
  • 举报
回复
05里边直接有checkbox列?我晕,没用过
sdl2005lyx 2006-11-21
  • 打赏
  • 举报
回复
liujia_0421():你干脆建议lz看MSDN啊!

到vs2005为止,listview控件只能提供第一列的checked属性,它是针对行的。
如果要使其他列有这样功能,我们必须扩展listview。

倒是在vs2005中,DataGridView控件有这样的功能,lz可以仔细看看msdn。
liujia_0421 2006-11-21
  • 打赏
  • 举报
回复
给你个例子:

private void CreateMyListView()
{
// Create a new ListView control.
ListView listView1 = new ListView();
listView1.Bounds = new Rectangle(new Point(10,10), new Size(300,200));

// Set the view to show details.
listView1.View = View.Details;
// Allow the user to edit item text.
listView1.LabelEdit = true;
// Allow the user to rearrange columns.
listView1.AllowColumnReorder = true;
// Display check boxes.
listView1.CheckBoxes = true;
// Select the item and subitems when selection is made.
listView1.FullRowSelect = true;
// Display grid lines.
listView1.GridLines = true;
// Sort the items in the list in ascending order.
listView1.Sorting = SortOrder.Ascending;

// Create three items and three sets of subitems for each item.
ListViewItem item1 = new ListViewItem("item1",0);
// Place a check mark next to the item.
item1.Checked = true;
item1.SubItems.Add("1");
item1.SubItems.Add("2");
item1.SubItems.Add("3");
ListViewItem item2 = new ListViewItem("item2",1);
item2.SubItems.Add("4");
item2.SubItems.Add("5");
item2.SubItems.Add("6");
ListViewItem item3 = new ListViewItem("item3",0);
// Place a check mark next to the item.
item3.Checked = true;
item3.SubItems.Add("7");
item3.SubItems.Add("8");
item3.SubItems.Add("9");

// Create columns for the items and subitems.
listView1.Columns.Add("Item Column", -2, HorizontalAlignment.Left);
listView1.Columns.Add("Column 2", -2, HorizontalAlignment.Left);
listView1.Columns.Add("Column 3", -2, HorizontalAlignment.Left);
listView1.Columns.Add("Column 4", -2, HorizontalAlignment.Center);

//Add the items to the ListView.
listView1.Items.AddRange(new ListViewItem[]{item1,item2,item3});

// Add the ListView to the control collection.
this.Controls.Add(listView1);
}
liujia_0421 2006-11-21
  • 打赏
  • 举报
回复
直接listView1.CheckBoxes = true;
即可...
fly_Jerry 2006-11-21
  • 打赏
  • 举报
回复
例如表中中Deleted为int,1表示已删除,0表示未删除

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧