WinForms ComboBox vs WebForms DropDownList

M

Mark Rae

Hi,

Just looking for some v2 guidance here...

In WebForms, the DropDownList control has an Items collection which contains
ListItem objects which, in turn, very conveniently contain a text property
and a value property.

In WinForms, the ComboBox control also has an Items collection which can
contain (as I understand it) pretty much any object which can display
something. However, virtually all of the examples I've seen on the Internet
(and certainly all of those in MSDN) demonstrate how to add string values to
a ComboBox. That's fine, of course, but what if you want to display a string
but hold an internal reference to, e.g., a numerical ID? Bog-standard
database stuff.

I've found a whole slew of examples showing how to do this by writing
wrapper classes and God knows what, but I'm thinking thus:

since the ComboBox Items collection can be a collection of any displayable
..NET objects, is there anything wrong with doing this?

MyComboBox.Items.Add(new System.Web.UI.Controls.ListItem("One", "1"));
MyComboBox.Items.Add(new System.Web.UI.Controls.ListItem("Two", "2"));
MyComboBox.Items.Add(new System.Web.UI.Controls.ListItem("Three", "3"));

Just because it's a WinForms app, is there anything intrinsically wrong with
using one of the Web namespaces? It's just another part of the Framework,
right? Just as I could use the VisualBasic namespace in C# if I really
wanted to (e.g. to use IsNumeric, or whatever)...

Any assistance gratefully received.

Mark
 
G

Guest

Mark,
Obviously you already understand the difference between the web version and
the Winforms versions.

So, I think the real question is "Does it work?". If it works, and this
makes you feel, better, then "knock yerself out", IMHO.
Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top