?
Solved

adding items in CheckedListBox control as  a key - value

Posted on 2005-03-09
4
Medium Priority
?
1,711 Views
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 !!!
0
Comment
Question by:DahaR
[X]
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
4 Comments
 
LVL 14

Expert Comment

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

itsvtk
0
 
LVL 8

Expert Comment

by:gena17
ID: 13494965
0
 
LVL 10

Accepted Solution

by:
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;
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
 
LVL 10

Expert Comment

by:smegghead
ID: 13495198
Thanks for my grade 'B'

A's make people much happier !!
0

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