ComboBox Items

  • Thread starter Thread starter Marius Horak
  • Start date Start date
M

Marius Horak

What are they for (VS2005)?
If I use an ArrayList as ComboBox.DataSource all is OK.
When I add each object from that list using Items.Add, setting
SelectedValue does not select an Item.

Is M$ doing this on purpose to annoy me?

MH
 
Some users may find using Items collection simpler than using
DataSource/DataMember/valueMember in cases where they want a simple
dropdown such as this one-liner:

this.comboBox1.Items.AddRange(new string[] { "one", "two",
"three" });

=======================
Clay Burch
Syncfusion, Inc.
 
ClayB said:
Some users may find using Items collection simpler than using
DataSource/DataMember/valueMember in cases where they want a simple
dropdown such as this one-liner:

this.comboBox1.Items.AddRange(new string[] { "one", "two",
"three" });

But what is the practical point of this if SelectedValue does not work.

MH
 
SelectedIndex works fine and SelectedItem returns the selected item as
expected.

void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
this.Text = comboBox1.SelectedIndex.ToString() + " | " +
comboBox1.SelectedItem.ToString() ;
}
================
Clay Burch
Syncfusion, Inc.
 
ClayB said:
SelectedIndex works fine and SelectedItem returns the selected item as
expected.

And we should be thankful to M$ for giving us such wonderful software.
It keeps us busy and in job (as we have to find a workaround).
But would you buy a car that only three wheels, out of four, are
working?

MH
 
As documented, SelectedValue refers to the value of the *Property*
specified in the ValueMember setting.

http://msdn2.microsoft.com/en-us/library/system.windows.forms.listcontrol.selectedvalue(VS.80).aspx

When you initialize a combobox with simple code such as

this.comboBox1.Items.AddRange(new string[] { "one", "two",
"three" });

there is no setting of the ValueMember propery, and hence, no support
for the SelectedValue or SelectedValueChanged.

As far as buying a car where you could use it in a 3-wheel mode or a 4-
wheel mode at your option, and the 3-wheel mode saved you $ (time) in
certain situations without adversely affecting the 4-wheel mode, then
that sounds like a win-win situation. It just offers you a simpler way
to use a tool.

===============
Clay Burch
Syncfusion, Inc.
 
Back
Top