【发布时间】:2013-02-28 14:17:12
【问题描述】:
我有一个 ListView,其中 MultiSelect = false、View = Details 和 CheckBoxes = True。我正在逐步完成它并控制应用程序中的可见性。我目前只使用下面代码的 Else 部分。但它不考虑第一个项目被选中,它只是打开第二个项目。以及该项目是否被选中(已经可见),它会关闭可见性。我正在将与项目关联的元素与已经可见的元素进行比较。我的应用程序在 currentItem.Checked 循环中崩溃。并且不考虑组合(首先和检查)。我该如何编码?
int indexCount = listView1.Items.Count;
ListViewItem currentItem = listView1.SelectedItems[0];
int currentIndex = currentItem.Index;
if (currentItem.Index == 0)
{
//listView1.SelectedItems[0] on
}
if (currentItem.Index == indexCount)
{
//end
}
if (currentItem.Checked == true)
{
while (currentItem.Checked == true)
{
listView1.SelectedIndices.Clear();
listView1.SelectedIndices.Add(currentIndex + 1);
}
//listView1.SelectedItems[0] on
}
else
{
//listView1.SelectedItems[0] off
listView1.SelectedIndices.Clear();
listView1.SelectedIndices.Add(currentIndex + 1);
//listView1.SelectedItems[0] on
}
【问题讨论】:
-
我不太明白你想要达到什么目的,你能补充一点细节吗?
-
我们需要崩溃原因的错误信息。
-
我认为您正在删除这些项目,并且由于 currentItem 是对其中一个指标的引用,因此当您使用 Clear 方法时,您正在处理它。所以你 currentItem 变成了一个空值。
-
我正在遍历 ListView 打开和关闭元素。如果项目被选中,跳过它。如果是第一个,打开它,而不是下一个。在链接的图像中,当我点击 Next 时,IRRIGATION 会继续。我再次点击下一步,IRRIGATION 将停止,它会跳过 PROCESS WASTE(因为它已经可见,已选中),然后打开 Lab Waste。 [链接]topofsteel.com/Images/ListView.png没有错误信息。它冻结 ctrl-alt-del
标签: c# winforms listview logic