【发布时间】:2018-12-11 12:00:09
【问题描述】:
我想通过从 ListView 中选择一个复选框来自动选择 ListView 中的所有复选框来编写代码。
我使用的是 Visual Studio 2005,所以我没有 ItemChecked 表单。 这就是为什么我想通过使用 ListView itemcheck 事件来做到这一点。这是我的代码。
private void lvBase_ItemCheck_1(object sender, ItemCheckEventArgs e)
{
if ( ) // If selecting one checkbox from the ListView
{
for (int i = 0; i < lvBase.Items.Count; i++)
{
// Select all checkbox from the ListView
}
}
else // If unselecting one checkbox from the ListView
{
for (int i = 0; i < lvBase.Items.Count; i++)
{
// Unselect all checkbox from the ListView
}
}
}
你能帮我填写一下吗?或者如果你有更好的想法,请分享:)
【问题讨论】:
-
您应该遍历 Items 集合并为每个集合设置 Checked 属性。
-
感谢您的回复!我不擅长 C#,但你的意思是“lvBase.Items[i].Checked == true”吗?我不知道在“如果”中填写什么。你能帮我吗?
-
这是一个不同的问题。查看 checkAll 或其他内容的 listview 属性 - 抱歉,我自己不确定