如何在ListView C#中同时实现复选框和选择 [英] How do I achieve both check box and selection simultaneously in listview C#
本文介绍了如何在ListView C#中同时实现复选框和选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
无论何时选中此复选框,都应选择相应的项目,反之亦然
我尝试过的事情:
Itemchecked事件我只是将选定的属性分配给选中的项目
示例:
Whenever the checkbox is checked the corresponding item should be selected and vice versa
What I have tried:
Itemchecked event i just assign the selected property to the checked item
Example :
private void listview_ItemChecked(object sender, ItemcheckedEventArgs e)
{
e. item. Selected = e. item. Checked;
}
推荐答案
列表listBox2_selectionhistory = new List();
私有无效checkedListBox2_SelectedIndexChanged(对象发送者,EventArgs e)
{
int actualcount = listBox2_selectionhistory.Count;
如果(实际计数== 1)
{
如果(Control.ModifierKeys == Keys.Shift)
{
int lastindex = listBox2_selectionhistory [0];
int currentindex = CheckedListBox2.SelectedIndex;
int upper = Math.Max(lastindex,currentindex);
int lower = Math.Min(lastindex,currentindex);
for(int i = lower; i< upper; i ++)
{
CheckedListBox2.SetItemCheckState(i,CheckState.Checked);
}
}
listBox2_selectionhistory.Clear();
listBox2_selectionhistory.Add(checkedListBox2.SelectedIndex);
}
其他
{
listBox2_selectionhistory.Clear();
listBox2_selectionhistory.Add(checkedListBox2.SelectedIndex);
}
}
我想这应该对你有帮助
List listBox2_selectionhistory = new List();
private void checkedListBox2_SelectedIndexChanged(object sender, EventArgs e)
{
int actualcount = listBox2_selectionhistory.Count;
if (actualcount == 1)
{
if (Control.ModifierKeys == Keys.Shift)
{
int lastindex = listBox2_selectionhistory[0];
int currentindex = checkedListBox2.SelectedIndex;
int upper = Math.Max(lastindex, currentindex) ;
int lower = Math.Min(lastindex, currentindex);
for (int i = lower; i < upper; i++)
{
checkedListBox2.SetItemCheckState(i, CheckState.Checked);
}
}
listBox2_selectionhistory.Clear();
listBox2_selectionhistory.Add(checkedListBox2.SelectedIndex);
}
else
{
listBox2_selectionhistory.Clear();
listBox2_selectionhistory.Add(checkedListBox2.SelectedIndex);
}
}
i thnk this should help u
这篇关于如何在ListView C#中同时实现复选框和选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文