473,770 Members | 4,198 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Hidden data in ListBox/ListView items?

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?

Nov 25 '07 #1
2 10646
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.
<ma******@gmail .comwrote in message
news:08******** *************** ***********@w40 g2000hsb.google groups.com...
>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?
Nov 25 '07 #2
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Stephany Young" <noone@localhos twrote in message
news:es******** ******@TK2MSFTN GP03.phx.gbl...
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.
<ma******@gmail .comwrote in message
news:08******** *************** ***********@w40 g2000hsb.google groups.com...
>>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?
Nov 25 '07 #3

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

Similar topics

2
12410
by: TF | last post by:
Hi, Is there any way to change the text color of SOME of the ListBox(Windows Forms Control) items in VB.NET? TF
1
5933
by: Liz | last post by:
I have used a ListView with several columns and lines to display an array ListView1.Items.Clear(); ListView1.Items.Add(aClients.Id); ListView1.Items.Add(aClients.Id); ListView1.Items.SubItems.Add(aClients.Surname); ListView1.Items.SubItems.Add(aClients.Forename); ListView1.Items.SubItems.Add(aClients.Surname);
6
11538
by: Adam Klobukowski | last post by:
Hello. /windows forms/ I'm marking listbox items as selected, and I'd like to scroll listbox to a selected entry if it is off-screen. How can I do it? -- Semper Fidelis Adam Klobukowski
2
23361
by: John R. | last post by:
I want to have a listbox that shows a checkbox and a textbox. I created a user control that has a checkbox and a textbox in it and have been trying to add it to a listbox but I can't get it to show up for each item I add to the listbox. foreach (Column column in columns) { ColumnsListBox.Items.Add(column.Name); ColumnsListBox.Controls.Add(new ColumnListControl(true, column.Name,
2
5743
by: Matt Sawyer | last post by:
Hi, I'm attempting to do a drag and drop operation from one listbox to another. I have my listboxes setup with SelectionMode = MultiExtended so that I can use the shift key, cntrl key, etc. to make multiple selections. The problem I am having is that when I use the shift key to select a range of items, I first click on one item (item gets highlighted), then, holding down the shift key, I select another item (the range of items gets...
4
5473
by: Brandon Potter | last post by:
I think I'm going crazy, but I cannot remember how to create a listbox with multiple columns as well as the sortable header block (a la Outlook message list). I've seen the examples of how to structure items in a listbox into "columns" by comparing the string length and adding white space but I was at some point able to do it similar to a DataGrid with the ListBox look. Does anyone have this code? Thanks, Brandon
4
2091
by: Duncan Smith | last post by:
So far, the quikest way I have found to select all items in a list box is to turn off updates, set a wait cusror and then call SetSelected on each item (see below), but it's too slow when the control is populated with tens of thousands of items. Ideally the wait-cursor shouldn't be needed as I hadn't anticipated a select-all operation taking a noticeable amount of time. Has anyone found a way to make this appear instantaneous as it...
4
7553
by: Thomas Adler | last post by:
Hello, I want to create a listbox with icons. Icon1 --- Item1 ----comment01 Icon1 --- Item2 ----comment01 Icon1 --- Item3 ----comment01 Icon2 --- Item4 ----comment01 Icon1 --- Item5 ----comment01 Icon2 --- Item6 ----comment06
6
4718
by: Mike | last post by:
Is there a way to get a ListView control to fire its SelectedIndexChanged event like the ListBox control? When the user selects multiple items at once, the ListView fires the event as each item gets selected. The ListBox waits to fire the event until all selections are complete. Thanks, Mike
0
9425
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
10231
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
10005
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
9871
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6679
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();...
0
5313
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5452
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3972
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
3576
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.