473,542 Members | 2,701 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ListView selected items

GTi
I have a listview that with selected items.
But I want to "reselect" items after a refresh.
Each items have a uniqe value in the Tag object.
After a refresh some new items may be added or removed
so using item index is not possible.

To get the list of selected items I use:
ListView.Select edListViewItemC ollection selItems =
this.listView1. SelectedItems;

And to get the currrent focused item (may not be selected):
focusItem = this.listView1. FocusedItem;

But how can I reselect items after a refresh, including the focused item ?
foreach(ListVie wItem item in selItems)
{
?????
}
Nov 17 '05 #1
7 24093
Hi!

GTi wrote:
I have a listview that with selected items.
But I want to "reselect" items after a refresh.
Each items have a uniqe value in the Tag object.
After a refresh some new items may be added or removed
so using item index is not possible.

To get the list of selected items I use:
ListView.Select edListViewItemC ollection selItems =
this.listView1. SelectedItems;

And to get the currrent focused item (may not be selected):
focusItem = this.listView1. FocusedItem;

But how can I reselect items after a refresh, including the focused item ?
foreach(ListVie wItem item in selItems)
{
?????
}


The selected items will no longer be present in the ListView after a refresh
(usually, you will create new items based on your collection). So, instead
of remembering this.listView1. SelectedItems, remember their tag values:
(Warning: untested pseudocode)

ArrayList selectedTags = new ArrayList();

foreach (ListViewItem item in selItems)
{
selectedTags.Ad d(item.Tag);
};
To reselect the items, iterate over this.listView1. Items:

foreach (ListViewItem item in this.listView1. Items)
{

if (selectedTags.I ncludes(item.Ta g))
{
item.Selected = true;
};
};
Nov 17 '05 #2
GTi
"Michael Voss" <mi************ ********@lvrREM OVE.CAPSde> wrote in message
news:42a01f0a$1 @news...
Hi!

GTi wrote:
I have a listview that with selected items.
But I want to "reselect" items after a refresh.
Each items have a uniqe value in the Tag object.
After a refresh some new items may be added or removed
so using item index is not possible.

To get the list of selected items I use:
ListView.Select edListViewItemC ollection selItems =
this.listView1. SelectedItems;

And to get the currrent focused item (may not be selected):
focusItem = this.listView1. FocusedItem;

But how can I reselect items after a refresh, including the focused item
?
foreach(ListVie wItem item in selItems)
{
?????
}
The selected items will no longer be present in the ListView after a
refresh
(usually, you will create new items based on your collection). So, instead
of remembering this.listView1. SelectedItems, remember their tag values:
(Warning: untested pseudocode)

ArrayList selectedTags = new ArrayList();

foreach (ListViewItem item in selItems)
{
selectedTags.Ad d(item.Tag);
};
To reselect the items, iterate over this.listView1. Items:

foreach (ListViewItem item in this.listView1. Items)
{

if (selectedTags.I ncludes(item.Ta g))
{
item.Selected = true;
};
};


THANKS!!!
Looks nice, but...if (selectedTags.I ncludes(item.Ta g))

..Includes is unknown...

I can't find anything similar.

Nov 17 '05 #3
Hi !

GTi wrote:

[...snip...]
THANKS!!!
Looks nice, but...
if (selectedTags.I ncludes(item.Ta g))

.Includes is unknown...

I can't find anything similar.


That's why I wrote:

[...snip...]
(Warning: untested pseudocode)

[...snip...]

You might want to write another method like:

private bool includes(ArrayL ist list, object testObject)
{
foreach (object item in list)
{
// Here, you might want to use a different
// comparison, maybe item == testObject
// or (int)item == int(testObject) ,
// depending on your unique tags

if (item.Equals(te stObject))
return true;
}

return false;
}
and call it like

if (this.includes( selectedTags, item.Tag))
{
....
};

Wouldn't it be nice if we could extend existing classes ;-)
Nov 17 '05 #4
Oops...

That
// or (int)item == int(testObject) , -----------------------^^^^^^^^^^^^^^^

should have read:
// or (int)item == (int)testObject


of course!
Nov 17 '05 #5
GTi
"Michael Voss" <mi************ ********@lvrREM OVE.CAPSde> wrote in message
news:42a023b7@n ews...
Hi !

GTi wrote:

[...snip...]
THANKS!!!
Looks nice, but...
>if (selectedTags.I ncludes(item.Ta g)) .Includes is unknown...

I can't find anything similar.


That's why I wrote:

[...snip...]
> (Warning: untested pseudocode)

[...snip...]

You might want to write another method like:

private bool includes(ArrayL ist list, object testObject)
{
foreach (object item in list)
{
// Here, you might want to use a different
// comparison, maybe item == testObject
// or (int)item == int(testObject) ,
// depending on your unique tags

if (item.Equals(te stObject))
return true;
}

return false;
}
and call it like

if (this.includes( selectedTags, item.Tag))
{
...
};

Wouldn't it be nice if we could extend existing classes ;-)


Michael,
I know the code was untested, and I really appreciate your contribute to
learn
up an newbie.
Wouldn't it be nice if we could extend existing classes ;-)

But we can do it, Create a new class and then inheritance the ListView
class.
But we loose the design view ...... (?)

Nov 17 '05 #6
GTi wrote:
[...snip...]
Wouldn't it be nice if we could extend existing classes ;-)

But we can do it, Create a new class and then inheritance the ListView
class.

[...snip...]

That's not what I call extending a class beacuse you'd effectively create a
new class (one you don't really need). I would like to add a method like
"public bool includes(object item)" to some _existing_ classes like
"ArrayList" or "CollectionBase "...
Nov 17 '05 #7
GTi
I know what you mean now,
Yeah, that would be nice.
Missing a contribute keyword.

In c/WIN32 it was possible to
Subclassing functions.
I don't know how this is done in C# (yet)

"Michael Voss" <mi************ ********@lvrREM OVE.CAPSde> wrote in message
news:42a02e57$1 @news...
GTi wrote:
[...snip...]
> Wouldn't it be nice if we could extend existing classes ;-)

But we can do it, Create a new class and then inheritance the ListView
class.

[...snip...]

That's not what I call extending a class beacuse you'd effectively create
a
new class (one you don't really need). I would like to add a method like
"public bool includes(object item)" to some _existing_ classes like
"ArrayList" or "CollectionBase "...

Nov 17 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
9699
by: Paddy | last post by:
How do I select a subitem from a listview after clicking on the first column? Couldn't find it in MSDN. Thank you. Paddy.
13
3733
by: Maheshkumar.R | last post by:
hi groups, I have placed an listview control, i want to iterate thru the control and find the clicked event items. listView2.Items.Add(fname.ToString(), i); how i can perform the iteration to find the item clicked...? and its item. thankz-- Mähésh Kumär. R
1
4002
by: Shane | last post by:
I have a text box select items in a listview as text is being typed into the text box. I get the select bar to move correctly in the Listview control. If the user presses the down or up key in the text box, I want to move to the selected item in the listview box. The down or up arrow does set focus to the listview box and the selected...
4
4929
by: Shane | last post by:
I have a text box select items in a listview as text is being typed into the text box. I get the select bar to move correctly in the Listview control. If the user presses the down or up key in the text box, I want to move to the selected item in the listview box. The down or up arrow does set focus to the listview box and the selected...
21
5175
by: StriderBob | last post by:
Situation : FormX is mdi child form containing 2 ListViews ListView1 contains a list of table names and 4 sub items with data about each table. ListView2 contains a list of the columns on each table and 11 sub items with data about each column. When a Row in ListView1 is selected the Data in ListVies2 is loaded to show the correct data....
2
6265
by: Mike | last post by:
Ok I'm having a problem with a listview. I have a listview on a WinForm called ProgramInformationFrm. I call this from from 2 other forms. One is ProgramSearch Frm, the other is OpenNCFrm. The search form accepts criteria from a user ans searches a sql table for any nc program that matches the criteria. The open form gives the user a list of...
5
10066
by: Phill W. | last post by:
(VB'2003) What's the correct way to remove multiple, selected items from a ListView control (say, from a ContextMenu)? I ask because I'm getting a very annoying ArgumentOutOfRangeException because the ListView seems to be trying to "re-select" items that are no longer there! for example, giventhat I have 3 items in my list: Select the...
4
13839
by: Bill-R | last post by:
I'm trying to convert a vb6 program to vb.net (vb2008 express) I have text data in a Listview Control I use a Textbox to enter characters to search the Listview When a Match is found, I use textbox_textchanged to select listview item Listview1.Items(z).Selected = True Listview1.Items(z).EnsureVisible () Listview1.Items(z).FullRowSelect...
0
1443
by: lsharva | last post by:
Actually, i m working on Windows Application where i have to use the ComboBox and listview in a way , as first we will click the comboBox and then as you click , ListView appear and when we select something , that will be selected at comboBox also and ListView will disappear, and comboBox item should get selected. Here i m having a problem as...
0
7397
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7336
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7726
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7675
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5877
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5257
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3384
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3385
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
948
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.