471,618 Members | 1,487 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,618 software developers and data experts.

ListView question

Hi all,
I posted the following in microsoft.public.dotnet.framework.windowsforms
but it seems that group has little traffic.

Hi all,

I have a listview box which is populated from methods of objects stored in
a List<T> collection. The
items in this collection are generated from a user filled out form.
The items in the listview have the same index as the ones in List<T>, so I
have an event which loops through the ListView, and if selected = true, the
data from the corresponding List<T> is used to populate a form - so in
effect creating an edit function. On Editing the data, the ListView is
regenerated, reading it's needed data from List<T> items (effectively
updating itself).
Is there any easier way to do this? It works fine, but I want to add search
capabilities to the ListView items, which if sorted, would no longer share
the same index as the List<T> items. One solution is to resort List<T>
(perhaps having a TempList<T>) so as to show only specific items and ensure
List<T> and ListView indexes still match. Or should I create a int field of
the List<T> items which has a permanent unique index and use this?

What is usually done in such circumstances?
Any help would be appreciated,

Chris

Ps if this isn't the right NG for these sort of questions, please let me
know where I should post them :).
Dec 27 '05 #1
1 2776
Hi,
"Chris" <mi*********@gmail.com> wrote in message
news:Jh******************@fe3.news.blueyonder.co.u k...
Hi all,
I posted the following in microsoft.public.dotnet.framework.windowsforms
but it seems that group has little traffic.

Hi all,

I have a listview box which is populated from methods of objects stored in
a List<T> collection. The
items in this collection are generated from a user filled out form.
The items in the listview have the same index as the ones in List<T>, so I
have an event which loops through the ListView, and if selected = true,
You can use ListView.SelectedItems no need to iterate in all the items in
the listview.
the
data from the corresponding List<T> is used to populate a form - so in
effect creating an edit function. On Editing the data, the ListView is
regenerated, reading it's needed data from List<T> items (effectively
updating itself).
Is there any easier way to do this?
Not quite understand what you are saying, if you update the corresponding
item in the List<T> and them you bind again the listview ( you do not say if
using bind ) then the answer is yes, that is the way of doing. If you
populate your listview manually you could just update the SubItems of the
item in question. and it's going to be faster this way.

It works fine, but I want to add search
capabilities to the ListView items, which if sorted, would no longer share
the same index as the List<T> items. One solution is to resort List<T>
(perhaps having a TempList<T>) so as to show only specific items and
ensure
List<T> and ListView indexes still match. Or should I create a int field
of
the List<T> items which has a permanent unique index and use this?

What is usually done in such circumstances?


What I do is inherit from ListViewItem and add a new property wich return a
reference to the object I'm holding, then you have direct access to the
object and you do not need to sync the view from the model ( the list ).

Take a look at MVC pattern in wikipedia

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Dec 27 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by J_Max | last post: by
7 posts views Thread by Dave Y | last post: by
3 posts views Thread by MikeY | last post: by
1 post views Thread by Derck | last post: by
12 posts views Thread by J L | last post: by
12 posts views Thread by garyusenet | last post: by
1 post views Thread by =?Utf-8?B?THluYkBtcy5jb20=?= | last post: by
5 posts views Thread by Mark Olbert | last post: by
reply views Thread by leo001 | last post: by
1 post views Thread by ZEDKYRIE | last post: by

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.