Hidden data in ListBox/ListView items?

M

markliam

I have a ListBox that is displaying a formatted string based on the
contents of a DataSet. The purpose of the listbox is for the user to
select an entry to delete, but I'm not sure how to match the listbox
entry with the corresponding DataRow.

The DataRow contains a unique id, but the id is not displayed in the
formatted string that appears in the listbox. Is there a way to
associate the id of the DataRow with the Listbox item so I know which
DataRow id to delete based on which listbox item is selected?
 
S

Stephany Young

Simply add another column to the ListView, set it's Visible property to
False and insert the unique id from the DataRow in that column.

When the user selects a row in the ListView, parse the content of the hidden
column and voila.
 
N

Nicholas Paldino [.NET/C# MVP]

I think a better idea is to set the Tag property on the ListViewItem to
the id of the corresponding DataRow. This way, you don't have to deal with
extra columns, etc, etc.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top