在Virtual ListView中选择项目的有效方法 [英] Efficient way of selecting an item in a Virtual ListView

查看:87
本文介绍了在Virtual ListView中选择项目的有效方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我正在尝试使用

虚拟模式找到在ListView中选择项目的最佳方法。我的物品是业务类,一旦我想选择(从另一个对话框传递),我就会引用

。一种方法是通过项目旋转

并将.Tag属性与我的业务对象进行比较(代码

以下),但我担心演员阵容可能代价高昂(可能很多

的服务器)。我还考虑过旋转服务器列表并直接比较

,然后使用索引设置所选项目,但是

使用foreach(),我不是我有索引号,而且我不确定for(int i ...)循环与foreach相比的

性能。我的代码

目前有效,但我想确保它尽可能快

(它会在很多地方,有很大的列表很快!)


List< Server> servers = Server.GetAll();

listServers.VirtualListSize = servers.Count;

if(server!= null)

{

foreach(listSerItem lvi in listServers.Items)

{

if(server ==(Server)lvi.Tag)

{

lvi.Selected = true;

休息;

}

}

}

解决方案

" Danny Tuppeny" < GR **** @ dannytuppeny.commmmmm>在留言中写道

news:43 *********************** @ ptn-nntp-reader04.plus.net ...

< snip>


我骗了 - 我的代码目前无效。 listView.Items在虚拟

模式中是空的...所以除了mots有效的方式之外,有没有人真的有

a方式有效?


我已经尝试过各种各样的方法,包括在

RetrieveVirtualItem方法中设置.Selected为true,但仍然没有喜悦:-(



服务器变量是否是对列表中你知道的实例的引用?

注意我没有用EXACT引用两个对象相同的值,但相同的

参考。

如果是这样,你不需要施法,它会比较参考,它会

尽可能快地获得:)

欢呼,

-

Ignacio Machin,

ignacio.machin AT dot.state.fl.us

佛罗里达州交通局


Danny Tuppeny < GR **** @ dannytuppeny.commmmmm>在留言中写道

news:43 *********************** @ ptn-nntp-reader04.plus.net ...

大家好,

我正在尝试使用
虚拟模式找到在ListView中选择项目的最佳方法。我的物品是业务类,一旦我想选择(从另一个对话框传递),我就会引用
。一种方法是通过项目旋转
并将.Tag属性与我的业务对象进行比较
(下面的代码),但我担心演员阵容可能代价高昂(可能会有很多服务器)。我还考虑过旋转服务器列表并直接比较,然后使用索引设置所选项目,然而使用foreach(),我没有索引号,我与foreach相比,我不确定for(int i ...)循环的性能。我的
代码目前有效,但我想确保它的速度和
一样快(它会在很多地方,很快就有很大的名单!)

List< Server> servers = Server.GetAll();
listServers.VirtualListSize = servers.Count;
if(server!= null)
{foreach(listSerItem lvi in listServers.Items)
{
if(server ==(Server)lvi.Tag)
{
lvi.Selected = true;
break;
}
}
}






什么是虚拟模式 ?


欢呼,

Danny Tuppeny < GR **** @ dannytuppeny.commmmmm>在消息中写道

news:43 ********************** @ ptn-nntp-reader01.plus.net ... < blockquote class =post_quotes>Danny Tuppeny < GR **** @ dannytuppeny.commmmmm>在消息中写道
新闻:43 *********************** @ ptn-nntp-reader04.plus.net ...
< snip>

我说谎 - 我的代码目前无效。 listView.Items在
虚拟模式中是空的...所以除了mots有效的方式,有没有人实际上有一种方法可行?

我试过了allsorts,包括设置。在RetrieveVirtualItem方法中选择为true,但仍然没有乐趣: - (



Hi All,

I''m trying to find the best way to select an item in a ListView using the
Virtual mode. My "items" are business classes, and I have a reference to
once I want to select (passed from another dialog). One way is to spin
through the items and compare the .Tag property to my business object (code
below), however I fear the casts are probably costly (there could be a lot
of servers). I also thought about spinning through the servers list and
comparing directly, then using the index to set the selected item, however
to use foreach(), I don''t have the index number, and I''m not sure of the
performance of a for(int i...) loop in comparison to a foreach. My code
currently works, but I''d like to make sure this is as fast as possible
(it''ll be in many places, with very big lists soon!)

List<Server> servers = Server.GetAll();
listServers.VirtualListSize = servers.Count;
if (server != null)
{
foreach(ListViewItem lvi in listServers.Items)
{
if (server == (Server)lvi.Tag)
{
lvi.Selected = true;
break;
}
}
}

解决方案

"Danny Tuppeny" <gr****@dannytuppeny.commmmmm> wrote in message
news:43***********************@ptn-nntp-reader04.plus.net...
<snip>

I lied - my code doesn''t currently works. listView.Items is empty in virtual
mode... So in addition to the mots efficient way, does anyone actually have
a way that works?

I''ve tried allsorts, including setting .Selected to true in the
RetrieveVirtualItem method, and still no joy :-(


Hi,
Is the server variable a reference to an instance you know is in the list?
note I''m not refering to two object with EXACT the same values, but the same
reference.
If so, you do not need to cast , it will compare the reference and it will
be as fast as you can get :)
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Danny Tuppeny" <gr****@dannytuppeny.commmmmm> wrote in message
news:43***********************@ptn-nntp-reader04.plus.net...

Hi All,

I''m trying to find the best way to select an item in a ListView using the
Virtual mode. My "items" are business classes, and I have a reference to
once I want to select (passed from another dialog). One way is to spin
through the items and compare the .Tag property to my business object
(code below), however I fear the casts are probably costly (there could be
a lot of servers). I also thought about spinning through the servers list
and comparing directly, then using the index to set the selected item,
however to use foreach(), I don''t have the index number, and I''m not sure
of the performance of a for(int i...) loop in comparison to a foreach. My
code currently works, but I''d like to make sure this is as fast as
possible (it''ll be in many places, with very big lists soon!)

List<Server> servers = Server.GetAll();
listServers.VirtualListSize = servers.Count;
if (server != null)
{
foreach(ListViewItem lvi in listServers.Items)
{
if (server == (Server)lvi.Tag)
{
lvi.Selected = true;
break;
}
}
}



Hi,

what is "virtual mode" ?

cheers,
"Danny Tuppeny" <gr****@dannytuppeny.commmmmm> wrote in message
news:43**********************@ptn-nntp-reader01.plus.net...

"Danny Tuppeny" <gr****@dannytuppeny.commmmmm> wrote in message
news:43***********************@ptn-nntp-reader04.plus.net...
<snip>

I lied - my code doesn''t currently works. listView.Items is empty in
virtual mode... So in addition to the mots efficient way, does anyone
actually have a way that works?

I''ve tried allsorts, including setting .Selected to true in the
RetrieveVirtualItem method, and still no joy :-(



这篇关于在Virtual ListView中选择项目的有效方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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