Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

adding items in CheckedListBox control as  a key - value

Posted on 2005-03-09
4
Medium Priority
?
1,792 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
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Suggested Courses

581 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