Re: ComboBox ItemData?

Tech-Archive recommends: Speed Up your PC by fixing your registry

From: Peter Foot [MVP] (feedback_at_no-spam.inthehand.com)
Date: 10/19/04


Date: Tue, 19 Oct 2004 08:41:35 +0100

You can bind the ComboBox to any custom object collection which exposes at
least the IEnumerable interface. You can then retrieve one of these custom
objects using the SelectedValue property. Another alternative is to use a
DataTable which you have filled from a database. You can specify which
property/field is used to display in the ComboBox as by default it will use
the objects ToString method. For a Customer you might use
comboBox1.DisplayMember = "CustomerName";
comboBox1.DataSource = customers;

Peter

-- 
Peter Foot
Windows Embedded MVP
www.inthehand.com | www.opennetcf.org
Do have an opinion on the effectiveness of Microsoft Windows Mobile and
Embedded newsgroups?  Let us know!
https://www.windowsembeddedeval.com/community/newsgroups
"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: ComboBox ItemData?
    ... So I'm not using the SelectedValue as suggested, nor the DataObject idea, ... >> I'm coming from MFC-land where a combobox had an ItemDataPtr property, ... >> Tim Johnson ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Linq-SQL canonical editable datagridview sample code
    ... Custom column is used to host virtual foreign key ComboBox. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Changed properties of control causes undesirable code
    ... constructor, I've hardcoded some initial items that I'd like added. ... When I add my control to a Form, the code-behind file contains code for each ... I suspect that there may be a way, within my ComboBox constructor, that I ... designer representation of custom controls very often. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Changed properties of control causes undesirable code
    ... constructor, I've hardcoded some initial items that I'd like added. ... When I add my control to a Form, the code-behind file contains code for each ... I suspect that there may be a way, within my ComboBox constructor, that I ... designer representation of custom controls very often. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: ComboBox - VBA
    ... I have a form that has a ComboBox object. ... custom Task Text1: ... I arbitrarily set the upper limit on the ...
    (microsoft.public.project)