ComboBox - adding item data


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: ComboBox - adding item data

  1. #1
    Mike Guest

    ComboBox - adding item data

    I know how to add data to combo boxes in C++, along with it's item data, but
    in C# I am having trouble getting more then a combo box with text. I need
    to be able to click on the combobox item and have a value that I can query a
    record with. Any ideas?

    --




  2. #2
    Patrick Steele [MVP] Guest

    Re: ComboBox - adding item data

    In article <3ca225f6$1@10.1.10.29> (from Mike <schome1@yahoo.com>),
    > I know how to add data to combo boxes in C++, along with it's item data, but
    > in C# I am having trouble getting more then a combo box with text. I need
    > to be able to click on the combobox item and have a value that I can query a
    > record with. Any ideas?


    The "Items" collection now accepts an "Object" type, not a string.
    Therefore, you can place whatever you want in the ListBox.

    For example, you could have a class that has 3 or 4 members like "Name",
    "Age", "DateOfBirth" and "ID". Simply add this class to the listbox as:

    Listbox.Items.Add(oTheClass)

    The listbox stores a reference to the class and then uses the
    "ToString" method of the class to populate the display of the listbox.
    You can override the ToString method to change what appears or you can
    set the "DisplayMember" property to tell the listbox what property to
    pick for display (Example: ListBox1.DisplayMember = "DateOfBirth").

    --
    Patrick Steele
    Microsoft .NET MVP

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center