473,399 Members | 2,858 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Listview problems

Hi everyone.

In a little program i am writing i have a listview, i fill it with data from
an ArrayList which contains a lot of objects. The data for the columns are
differente fields in the objects in the ArrayList.

I have also added column sorting, when a user clicks a column.
All that works fine.

But when a user double clicks a line in the listview (detail mode), an event
is raised, and i get the 'selectedItems' from the listview. From this list i
can find the data in the line that has been clicked.

But my problem is how du i figure out which object from the ArrayList this
line reflects ?

I can have 100% equal objects in the ArrayList.

I could of course add a unique ID for each object, but have not been able to
figure out how to add that to the ListView without showing it to the user.

Can anybody please help me ?

Best regards
Søren Reinke
Nov 17 '05 #1
5 1696
I noticed if a add data to a column that does not have a name, it is not
displayed, and then i can use it as an unique ID.

Is that an acceptable way to do it ?

Best regards
Søren Reinke
"Søren Reinke" <so***@reinke.fjernmig.dk> wrote in message
news:d3**********@newsbin.cybercity.dk...
Hi everyone.

In a little program i am writing i have a listview, i fill it with data
from an ArrayList which contains a lot of objects. The data for the
columns are differente fields in the objects in the ArrayList.

I have also added column sorting, when a user clicks a column.
All that works fine.

But when a user double clicks a line in the listview (detail mode), an
event is raised, and i get the 'selectedItems' from the listview. From
this list i can find the data in the line that has been clicked.

But my problem is how du i figure out which object from the ArrayList this
line reflects ?

I can have 100% equal objects in the ArrayList.

I could of course add a unique ID for each object, but have not been able
to figure out how to add that to the ListView without showing it to the
user.

Can anybody please help me ?

Best regards
Søren Reinke

Nov 17 '05 #2
You can use the ListViewItem.Tag property to store information about an
object:

http://msdn.microsoft.com/library/de...sstagtopic.asp
MyObject object = new MyObject("abcde");
ListViewItem item = new ListViewItem();
item.Text = "Some caption";
item.Tag = object;

--------------------------------

MyObject object = null;
ListViewItem item = mylistview.Items[0];
myobject = (MyObject)item.Tag;

Alex

"Søren Reinke" <so***@reinke.fjernmig.dk> wrote in message
news:d3**********@newsbin.cybercity.dk...
Hi everyone.

In a little program i am writing i have a listview, i fill it with data
from an ArrayList which contains a lot of objects. The data for the
columns are differente fields in the objects in the ArrayList.

I have also added column sorting, when a user clicks a column.
All that works fine.

But when a user double clicks a line in the listview (detail mode), an
event is raised, and i get the 'selectedItems' from the listview. From
this list i can find the data in the line that has been clicked.

But my problem is how du i figure out which object from the ArrayList this
line reflects ?

I can have 100% equal objects in the ArrayList.

I could of course add a unique ID for each object, but have not been able
to figure out how to add that to the ListView without showing it to the
user.

Can anybody please help me ?

Best regards
Søren Reinke

Nov 17 '05 #3
Hi Reinke,
add a Hidden Column in the listView that will contain the index of the
object, you will assing the index for every row you add so you will be able
to now the possition in the arrayList.
Hope that Helps
"Søren Reinke" <so***@reinke.fjernmig.dk> wrote in message
news:d3**********@newsbin.cybercity.dk...
Hi everyone.

In a little program i am writing i have a listview, i fill it with data
from an ArrayList which contains a lot of objects. The data for the
columns are differente fields in the objects in the ArrayList.

I have also added column sorting, when a user clicks a column.
All that works fine.

But when a user double clicks a line in the listview (detail mode), an
event is raised, and i get the 'selectedItems' from the listview. From
this list i can find the data in the line that has been clicked.

But my problem is how du i figure out which object from the ArrayList this
line reflects ?

I can have 100% equal objects in the ArrayList.

I could of course add a unique ID for each object, but have not been able
to figure out how to add that to the ListView without showing it to the
user.

Can anybody please help me ?

Best regards
Søren Reinke

Nov 17 '05 #4
Using the ListViewItem.Tag property is the correct way to do it. You
can store either an index value or a reference to the object itself in
the Tag, depending upon what you want to do.

I just wish that ComboBox entries had a Tag property, too. :(

Nov 17 '05 #5

"Alex Passos" <bz@netmerlin.nospam.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
You can use the ListViewItem.Tag property to store information about an
object:

http://msdn.microsoft.com/library/de...sstagtopic.asp
MyObject object = new MyObject("abcde");
ListViewItem item = new ListViewItem();
item.Text = "Some caption";
item.Tag = object;


Thanks for all the answers, the .Tag was just what i was looking for.

Best regards
Søren Reinke
Nov 17 '05 #6

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

Similar topics

9
by: Eva | last post by:
Hi, I wanted to know how i can enter values into a specific column of a listview. I have tried the following code but this seems to enter all my values into the first column!!! Can anyone...
1
by: MrB | last post by:
I am quite new to vb.net. I have been using VBA for years, but an having problems with populating a listview. I have tried many things, including snippets of code from some news groups with no...
6
by: Richard | last post by:
Hi. I use a ListView to display data in tabular form. Each ListView row corresponds to a data record. The ListView Item of the record is the record key or code. Each SubItem in that row...
3
by: pointBoarder | last post by:
I'm following the article from http://support.microsoft.com/default.aspx?scid=kb;en-us;155178 The above article explains how to fill a listview. For some reason I keep recieving "User-defined...
2
by: MikeY | last post by:
Hi all, I am coding window forms in C#. My problem is this: I have created a "Check ListView" or a 'ListView' with checkbox's. I have populated the it with my files from my folders, mps, txt,...
2
by: TarheelsFan | last post by:
I am having problems with drag and drop into a listview. I am able to drag and drop items from within the listview, as well as drag items from the listview and drop into a picturebox. However, I...
3
by: Michael.Suarez | last post by:
Is it me, or does it seem like they put no effort into creating the listview control in .Net. listview. A few gripes I have with .Net listview that aren't present in vb6: -Inability to set...
12
by: garyusenet | last post by:
I have had no replies to my previous post so perhaps I didn't write it good enough. Please excuse new thread but i wanted to break from the last thread hopefully this thread will be better. ...
0
by: Griff | last post by:
I have a Windows appliction that I want to turn into a WPF application (as a proof of concept). However, I have encountered a problem with the ListView object and I can't find any suitable help...
8
by: Lord Zoltar | last post by:
Hi, I've got a list view that displays a series of images. I'd like to be able to draw a divider across the list view to divide the images into groups. Ideally, I'd have a group name, with a line...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
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...

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.