adding items in CheckedListBox control as  a key - value

Posted on 2005-03-09
Medium Priority
Last Modified: 2008-02-01
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 !!!
Question by:DahaR
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 14

Expert Comment

by:Thandava Vallepalli
ID: 13494745
is it web application or windows application (form)


Expert Comment

ID: 13494965
LVL 10

Accepted Solution

smegghead earned 375 total points
ID: 13495117
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;

Hope this helps


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

Expert Comment

ID: 13495198
Thanks for my grade 'B'

A's make people much happier !!

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question