473,386 Members | 1,610 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,386 software developers and data experts.

checked item

I fill a checked listBox with data from dataset.

I would like, when a user checked one item , to save it in dataset.

The problem is that I don't know how to get its ID number, because I have
only a name ?

Hrcko
Nov 17 '05 #1
1 1662
"Hrvoje Voda" <hr*********@luatech.com> wrote in message
news:d5**********@ss405.t-com.hr...
I fill a checked listBox with data from dataset.
I would like, when a user checked one item , to save it in dataset.
The problem is that I don't know how to get its ID number, because I have
only a name ?


When you add items to the listbox, such as

lb.Items.Add(Name)
Instead of adding a string, create a small class that holds a name and an ID
and add the object instead:

class LbItem {
string _Name;
int _ID;

public LbItem(string Name, int ID) {
_Name = Name;
_ID = ID;
}

public override string ToString() {
return _Name;
}
}

To add the item to the listbox:
lb.Items.Add(new LbItem(Name, ID));
To get the checked items back out:

foreach (LbItem Item in lb.CheckedItems) {
int ID = Item.ID;
// etc.
}

This may have a few typos here since typing in by hand, not pasting...

-- Alan
Nov 17 '05 #2

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

Similar topics

2
by: Jerome | last post by:
Hi, I've got the following problem: I'm retrieving data from an SQL Server database. And I want my form to display a checked box in the state corresponding to the value saved in the DB. But...
3
by: Dean Slindee | last post by:
In a checked listbox, I am allowing drag/drop of the items within (resequencing). Problem is, when dropping a checked item, the checked state always reverts to unchecked (unwanted). Anyone know...
26
by: Simon Jefferies | last post by:
Hello, I am trying to add an item to a checked list box, like: clbList.Items.add("Hello",true) I get an error back: Run-time exception thrown: System.ArgumentOutOfRangeException -...
16
by: MSN | last post by:
xp pro/vs 2002/web forms/VB How do I make a checkbox checked when add it to a checkboxlist. Thanks
1
by: Dennis | last post by:
I have a checked list box and am trying to use the SetItemCheck method as follows: mylistbox.SetItemChecked(indextoset, True) It seems to have no effect and the display does not show the box...
1
by: sherifffruitfly | last post by:
Hi, I've got a checked list box, and a "go' button on the form. Each item in the checked list box is associated with a program (say notepad, calc, etc.). When the user clicks "go", every item...
4
by: spowel4 | last post by:
My form has a listview populated with the 50 states. When the user checks the checkbox within the listview for a particular state, I need to retrieve which state was checked (i.e. if AZ is checked...
6
by: painkiller | last post by:
language: vb.net environment: windows forms .net : v1.1 i am having a checkedlistbox control that display document category such as text, image, video, audio etc. these values are coming from...
0
by: Soulless | last post by:
Hi, I have reason to need to use a checked list box. The list box contents will be filled with filenames in a directory. These values will change. I need the ability to be able to select a...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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
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,...
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...

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.