Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hidden Values in Listview items?

Tags:

c#

Is There a way to add hidden values to a listview item?

I am creating a listview where I show data from a database. I also want to be able to edit this therefore I need two IDs to make sure it's the correct item and I don't mess up the database

Is there any way to do this? I Tried adding an ID to the TAG property of the list view item.

   ListViewItem track = new ListViewItem();
            track.Tag = id;
            track.Text = ("Test: " + SL[i] + " Test: " + SL[i + 1]);
            listView1.Items.Add(track);

But I need to add 2 IDs to an item.

EDIT: I am using Winforms

like image 434
Jasper Schiks Avatar asked Feb 22 '26 00:02

Jasper Schiks


1 Answers

Here are two ways to solve this:

You can extend ListViewItem in a new class and add your two properties to that class.

You can create a Tuple that contains both IDs and store that in the Tag.

like image 174
Jeffrey L Whitledge Avatar answered Feb 23 '26 17:02

Jeffrey L Whitledge