1、添加复选框:listView1.CheckBoxes = true;
2、选中listview并获取选中的数目:
private void listView1_ItemChecked(object sender, ItemCheckedEventArgs e)
{
e.Item.Selected = e.Item.Checked;
m = listView1.CheckedItems.Count;
label1.Text = "当前选中数:" + m.ToString();
}
说明:点击复选框或者双击listview均可选中某一行,但是跟comboBox控件不一样的是,获取选中数目要用:
本文介绍了如何在C#的ListView控件中添加复选框功能,并详细说明了如何通过设置listView1.CheckBoxes = true;来启用此功能。同时,文章讲解了如何正确获取选中项目的数量,需使用listView1.CheckedItems.Count而非listView1.SelectedItems.Count。此外,还提及了如何获取选定的多个复选框值。
订阅专栏 解锁全文
720

被折叠的 条评论
为什么被折叠?



