你可以在「的GotFocus」事件指派給一個方法,像這樣,記錄了「最後的焦點」控制這種方式。然後在你的SelectAll_CLick處理程序中,如果分配了listview,selectall,否則 - 不要!
private ListView mLastSelectedListView;
private void ListViews_GotFocus(object sender, EventArgs e)'
{
ListView lv = sender as ListView;
if (null == lv) return;
mLastSelectedListView = lv;
}
private void SelectAll_Click(object sender, EventArgs e)
{
if (null == mLastSelectedListView) return;
mLastSelectedListView.SelectAll();
}
下面是一個快速的'SelectAll'擴展方法來支持上述;
public static class ListViewExtensions
{
public static void SelectAll(this ListView lv)
{
foreach (ListViewItem item in lv.Items)
item.Selected = true;
}
}
你想選擇全部按鈕來選擇列表中用戶最後點擊的所有項目? –
@Boo:是...... – Bohn