我怎样才能在ListView中取消选择项目? [英] How can I unselect item in ListView?
问题描述
我有一对夫妇在这一个项目的ListView。当ListView控件失去焦点,最后选定ListViewItem的仍是选择带有灰色背景。
我想做到这一点的ListView.FocusLost,选择走了,因此ListView.SelectedIndexChanged事件将会发生。
任何想法?
I have a ListView with a couple of items in it. When the ListView looses focus, the last selected ListViewItem is still "selected" with a gray background.
I would like to achieve that on ListView.FocusLost, the selection is gone and therefore the ListView.SelectedIndexChanged event will occur.
Any ideas?
我使用.NET CF 3.5。
I am using .NET CF 3.5.
推荐答案
假设你是从父窗体/控制访问的ListView。
Suppose you are accessing the ListView from a parent form/control.
您可以在窗体的/控制的构造函数/ Load事件添加这块code:
You can add this piece of code in the form's/control's constructor/load event:
this.myListView.LostFocus += (s, e) => this.myListView.SelectedIndices.Clear();
好了,你的情况,你将取代该委托有:
Ok, so in your case, you would replace that delegate with:
if (this.myListView.SelectedIndices.Count > 0)
for (int i = 0; i < this.myListView.SelectedIndices.Count; i++)
{
this.myListView.Items[this.myListView.SelectedIndices[i]].Selected = false;
}
您可以给c进行更好的形式$ C $,顺便说一句。
You can give the code a nicer form, btw.
这篇关于我怎样才能在ListView中取消选择项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!