473,763 Members | 1,882 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can I index an IList/Collection associated with a ListView, after the ListView has been sorted?

I have an IList/Collection that contains items in a ListView.

If i click on an item in the ListView, i can capture the index
(lv.SelectedIte ms[0].Index) and reference the correct item in the
associated IList/Collection .

Once I've sorted the ListView, obviously the indices do not match up
anymore. So, should i sort the IList/Collection when I sort the
ListView (which seems overkill to me) or some how sort the indices
associated with the ListView?

I'm buffaloed at this point.

Any input is appreciated. Thanks guys (and gals).

Apr 9 '07 #1
4 13164
You should have a separate Dictionary which is keyed by the ListViewItem
to the object that you are visualizing in the list view. Then, you can
easily retrieve the item that the ListViewItem is referencing.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"forest demon" <me********@gma il.comwrote in message
news:11******** **************@ n59g2000hsh.goo glegroups.com.. .
>I have an IList/Collection that contains items in a ListView.

If i click on an item in the ListView, i can capture the index
(lv.SelectedIte ms[0].Index) and reference the correct item in the
associated IList/Collection .

Once I've sorted the ListView, obviously the indices do not match up
anymore. So, should i sort the IList/Collection when I sort the
ListView (which seems overkill to me) or some how sort the indices
associated with the ListView?

I'm buffaloed at this point.

Any input is appreciated. Thanks guys (and gals).

Apr 9 '07 #2
A different approach; I quite like observer-based patterns, so I use a
data-bound ListView subclass, and bind to a list that implements
IBindingList (SupportsSortin g/SortProperty/SortDirection) and
IBindingListVie w (SupportsAdvanc edSorting/ApplySort). I then ask the
list to sort itself, and let the UI manage itself. This can be quite a
handful from scratch, but from what I have seen so far the .Net 3.0
classes may offer some improved list classes (ObservableColl ection etc
- haven't checked to see if it supports sorting though), and WPF
offers more data-bound UI options for displaying data.
Finally, if you are using the Details view (of ListView), consider
switching to DataGridView, as again this is data-bound without needing
to code anything.

Marc
Apr 9 '07 #3
Additional: have checked, and unless I missed it, ObservableColle ction
does not appear to support sorting. Disappointing.

Marc

Apr 9 '07 #4
thanks for the input guys...what would i do without USENET input?

i ended up hashing it and i have it working as expected.

Apr 9 '07 #5

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

Similar topics

11
2205
by: Vani Murarka | last post by:
Hi Everyone, Does .NET offer any collection class which will give me objects last *accessed* such that I may build a least-recently-used cache that kills off objects that haven't been used for awhile? Or is there any other way to implement this kind of a cache / collection where one can do this kind of cleanup based on least-recently-used objects?
4
1846
by: Mr. B | last post by:
VB.net issue here. I've a strange event that I can't seem to figure out... On my Form, I've a TabControl (two Tabs)... On my first tab, I load an Ascii file and dump some info onto my ListView (which is located on my other Tab). Now IF I click on the 2nd Tab... the Info IS to be sorted out - as I've set
0
2032
by: Wiktor Zychla | last post by:
Hello, I am thinking of a general solution to the specific issue and I hope someone has some more experience on that. Up to now I use the ListView as the primary control for collections of items. Unfortunately, the ListView behaves sluggishly with large amounts of data. That's why I think of using DataGrid instead. The DataGrid in my application should be databinded to a memory
0
2563
by: Samuel R. Neff | last post by:
I'm having a index problem with ListView SubItems. If I add multiple columns to the listview and then add items with associated subitems, the ListView displays fine. Then if I delete a column via ListView.Columns.RemoveAt() then the ListView still displays fine. However, if I grab a subitem value via listView.Items.SubItems.Text Then I get the Text of the wrong column.
3
4218
by: ad | last post by:
Hi, When I studied CSharp, I am confuse by IList, Collection and Array. What is the relationships between them?
19
25466
by: Owen T. Soroke | last post by:
Using VB.NET I have a ListView with several columns. Two columns contain integer values, while the remaining contain string values. I am confused as to how I would provide functionality to sort columns based on the column header the user has clicked in both Ascending and Descending formats.
5
18478
by: gmccallum | last post by:
I am trying to create a base class that contains a collection that MUST be able to be referenced by both a string key and a positional index. This collection MUST keep the items in the same order as they are added. In 2.0, is there a collection that would support this? The List<> works to keep the order but doesn't allow me to reference the items by key like the Dictionary<> collection does, but I don't think the Dictionary collection...
12
2229
by: pamelafluente | last post by:
Hi guys, Is it possible to get the current index, when iterating with FOR EACH on some collection (implementing ILIST) without using and external counting variable (, that is somehow getting the internal enumerator) ? For Each SomeObj As Object In ArrayListObj
0
1437
by: biswal.srikant | last post by:
I've been trying to correct this error for approx 2 days and am having no luck. In a page's button clickevent , i want to bind a infragistic grid according to two dropdown value. At the first click it runs correctly, but when change the index of dropdown and again click that button, this gives an error message.
0
9566
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9389
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10149
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9943
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8825
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7370
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6643
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3918
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3529
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.