如何全选/选择无.NET 2.0中的ListView? [英] How to SelectAll / SelectNone in .NET 2.0 ListView?

查看:84
本文介绍了如何全选/选择无.NET 2.0中的ListView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是选择全部或选择列表视图中没有商品不使用的好方法:

What is a good way to select all or select no items in a listview without using:

foreach (ListViewItem item in listView1.Items)
{
 item.Selected = true;
}

foreach (ListViewItem item in listView1.Items)
{
 item.Selected = false;
}

我认识的基础Win32 ListView公共控件支持 LVM_SETITEMSTATE消息您可以使用设置选中状态,并通过将-1,因为这将适用于所有项目的索引。我宁愿不PInvoking消息,而恰好是在.NET列表视图控制背后的控制(我不希望是一个坏的开发商和靠无证行为 - 当他们将其更改为完全托管的ListView类)

I know the underlying Win32 listview common control supports LVM_SETITEMSTATE message which you can use to set the selected state, and by passing -1 as the index it will apply to all items. I'd rather not be PInvoking messages to the control that happens to be behind the .NET Listview control (I don't want to be a bad developer and rely on undocumented behavior - for when they change it to a fully managed ListView class)

<一个href=\"http://stackoverflow.com/questions/87101/how-to-selectall-selectnone-in-net-2-0-listview/87209#87209\">Pseudo受虐狂有选择无情况:

ListView1.SelectedItems.Clear(); 

现在只需要在全选 code

Now just need the SelectAll code

推荐答案

哇,这是旧的...:D

Wow this is old... :D

 listView1.BeginUpdate(); 
 foreach (ListViewItem i in listView1.Items)
 {
     i.Selected = true;
 }
 listView1.EndUpdate();

选择反

 listView1.BeginUpdate(); 
 foreach (ListViewItem i in listView1.Items)
 {
     i.Selected = !i.Selected;
 }
 listView1.EndUpdate();

的BeginUpdate EndUpdate 用于禁用/启用控制重绘,而其内容正在更新中...我想,这将选择所有的更快,因为它会刷新一次,而不是 listView.Items.Count 倍。

BeginUpdate and EndUpdate are used to disable/enable the control redrawing while its content is being updated... I figure it would select all quicker, since it would refresh only once, and not listView.Items.Count times.

这篇关于如何全选/选择无.NET 2.0中的ListView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆