Re: Fill a ComboBox

From: Scott (scottaf_at_yahoo.com)
Date: 02/17/04


Date: Tue, 17 Feb 2004 14:51:29 -0600

A simple way is to create a class to hold your data. The combobox uses the
System.Windows.Forms.ComboBox.ObjectCollection class to hold the items for
the combobox and uses the ToString() method to get the text to display.
Simply create a class that has a String and an Integer and add a ToString()
method to return the String value.

See this previous newsgroup post...

http://groups.google.com/groups?q=vb.net+combobox+item+tag&hl=en&lr=&ie=UTF-8&oe=utf-8&selm=e9ZFHeFXDHA.2524%40TK2MSFTNGP09.phx.gbl&rnum=1

"Pepehammer" <pepehammer@hotmail.com> wrote in message
news:OMRMrQZ9DHA.3404@TK2MSFTNGP09.phx.gbl...
> Hi everybody!
>
> I got a combobox to fill.
> I want to display some information (Text), but when I select a item, I
want
> to return a number.
>
> The info I want to fill in is something like this:
>
> TEXT VALUE
> Category1 10
> Category2 15
> Category3 35
>
> How can I perform this task?
>
> Thanks!
>
>
>
>
>



Relevant Pages

  • Re: Data in ComboBoxes
    ... DotNet that the item type is object and the control uses the ToString() ... method to figure out how to display it. ... public string ToString() ... > access the data of the combobox either by the items text or by its index. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Combobox display und value member
    ... Die Werte für Display und Valuemember sind Eigenschaftsnamen, welche jedes Object in der DataSource-Auflistung anbieten muss. ... Dadurch dass deine eingefügten Werte strings sind, kann deine Data oder Value Eigenschaft nur eine Property des String datentyps sein. ... Deine ComboBox weiss nichts von deinem Reader, damit kannst du auch keine Felder des Readers als Member angeben. ...
    (microsoft.public.de.german.entwickler.dotnet.csharp)
  • Re: newbie help for winform combo box needed
    ... You can create your own ListItem class or just put "30" and override the drawing algorithm to display the item text + " days". ... public string value1; ... The ComboBox will call ToString to determine what to display. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: ListItem not available in win forms
    ... You can put anything in a combobox, be it a string, int, float or a custom ... The combobox will call the ToString method of the object to find out ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: help - populating a combox box from a text file and updating a listbox automatically
    ... The item in the ComboBox have some text that should be displayed in the TextBox. ... This text is taken from another file and can be shared among several items in the ComboBox. ... you could also put it in the same file as the ComboBox values and store the text along with the display value. ... public string Display ...
    (microsoft.public.dotnet.languages.csharp)