Re: ComboBox ItemData?

From: Alex Feinman [MVP] (public_news_at_alexfeinman.com)
Date: 10/19/04


Date: Tue, 19 Oct 2004 00:44:04 -0700

In CF you need to approach this from the other end. Instead of adding
strings, add objects (or structures). The Combobox will use .ToString() on
each item to display it. You can create a structure, overrride its
ToString() and use it to populate combobox.
Alternatively an ArrayList of objects/strctures can be used as DataSource.
In this case the DisplayMember and ValueMember will be property names to
retrieve from the element
Finally use Combobox.SelectedItem to retrieve the selected item

-- 
Alex Feinman
---
Visit http://www.opennetcf.org
"Tim Johnson" <tjohnson@high-point.com> wrote in message 
news:eU55kFatEHA.1404@TK2MSFTNGP11.phx.gbl...
> I'm coming from MFC-land where a combobox had an ItemDataPtr property,
> whereby you could stash away a ptr to some arbitrary object.  Then when 
> the
> user selected an item, you could fetch the object back based on the 
> selected
> index.  Is there anything comparable in C#?  The only samples I've seen 
> show
> them managing their own separate arraylist corresponding to the items in 
> the
> combobox - yechh!
>
> -- 
> Tim Johnson
> High Point Software
> www.high-point.com
> (503) 312-8625
>
> 


Relevant Pages

  • Re: Arraylist question
    ... ToString virtual method in your PERSON class to return: ... public override string ToString() ... Now you can add the instances of person directly to the combobox which will ... > public int CompareTo ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Overwrite combobox to accept objects in constructor
    ... Are you referring to JComboBox? ... This way combobox for each object in vector invokes method ... > toString. ...
    (comp.lang.java.gui)
  • Re: Adding references to objects in a comboBox
    ... possible display strings ... one item is selected in the comboBox. ... ToString() for how would I know as to what to have the overridden ToString ... > obj is a reference to your object. ...
    (microsoft.public.dotnet.languages.csharp)
  • 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: Getting values between forms
    ... I'm have defined a combobox on form2 and I'm trying to use that value ... Public Shared TimerMinutes As ComboBox ... After this global value has been modified, I try to retrieve the value ...
    (microsoft.public.dotnet.languages.vb)