|
以下代码:为什么有时候当从下行往上行点选时还会选择两行?而从上行往下行点选时又不会。我感觉是:当从下往上点选时,下行选中状态没有释放
但我不知道怎么写代码?
//在成功验证控件之后
private void listView1_Validated(object sender, EventArgs e)
{
//listView1.MultiSelect = false;
if (listView1.FocusedItem != null)
{
listView1.FocusedItem.BackColor = SystemColors.Highlight;
listView1.FocusedItem.ForeColor = Color.White;
listView1.SelectedIndices.Add(listView1.FocusedItem.Index);//真正让其选择
}
}
//当选中状态更改时
private void listView1_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
{
e.Item.ForeColor = Color.Black;
e.Item.BackColor = SystemColors.Window;
if (listView1.FocusedItem != null)
{
listView1.FocusedItem.Selected = true;
}
}
|
|