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
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