adding items in CheckedListBox control as a key - value

i am workin on the CheckedlistBox  control and want to add the items in it , with index against each item , so that i get retrieve items based on that index

For Example:

i have a table

ID                         Names
-----                     --------

3                           abc
7                           def
9                           ghi
12                           jkl


now i want to fill the checkedlistbox with  the  'Names' , and also want to KEEP THE
'ID'  as the key against each item , so that i can retrieve the item and update the table  by the KEY (i,e the 'ID' ) against each item

i hope u get what i mean !!! :)

thanks....it wud be swell if i can get a immedciate reply with sum code snippet !!!
LVL 1
DahaRAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Thandava VallepalliCommented:
is it web application or windows application (form)

itsvtk
0
gena17Commented:
0
smeggheadCommented:
I'd use the following class and use the syntax

MyCLB.Items.Add(new ComboItem(3,"abc"));
MyCLB.Items.Add(new ComboItem(7,"def"));
MyCLB.Items.Add(new ComboItem(9,"ghi"));
MyCLB.Items.Add(new ComboItem(12,"jkl"));

Then, when you click on an item, cast it back to ComboItem and get its 'id' property.

ComboItem sel=(ComboItem)MyCLB.SelectedItem;
Console.WriteLine(sel.id);

Hope this helps
Smg

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

public class ComboItem
{
      public ComboItem(int InID,string InDesc,string InOther,object InTag)
      {
            _id=InID;
            _Desc=InDesc;
            _Other=InOther;
            _Tag=InTag;
      }
      public ComboItem(int InID,string InDesc,string InOther)
      {
            _id=InID;
            _Desc=InDesc;
            _Other=InOther;
            _Tag=null;
      }
      public ComboItem(int InID,string InDesc)
      {
            _id=InID;
            _Desc=InDesc;
            _Other=null;
            _Tag=null;
      }
      private int _id;
      private string _Desc;
      private string _Other;
      private object _Tag;
      public override string ToString()
      {
            return _Desc;
      }
      public int id
      {
            get{return _id;}
            set{_id=value;}
      }
      public string Desc
      {
            get{return _Desc;}
            set{_Desc=value;}
      }
      public string Other
      {
            get{return _Other;}
            set{_Other=value;}
      }
      public object Tag
      {
            get{return _Tag;}
            set{_Tag=value;}
      }
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
smeggheadCommented:
Thanks for my grade 'B'

A's make people much happier !!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.