DataBinding ComboBox

A

Aaron Prohaska

I am having a problem databinding a combobox that I have on a form. I
have setup the databinding in the following way.

this.flexibilityList.Items.AddRange(new object[] {"0", "1", "2", "3",
"4", "5", "6", "7", "8", "9", "10"});

I then add the binding like this.

this.measurement = new BusinessEntity();

this.flexibilityList.DataBindings.Add("Text", this.measurement,
"Flexibility");

One of the properties of the business entity are Flexibility so I assume
that this is supposed to map the Flexibility property to the values
created in the Items.AddRange method. Can anyone tell me why this isn't
updating the Flexibility property of my business object when I change a
value in the ComboBox?

Regards,

Aaron Prohaska

-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-
Wrench Science Inc.
http://www.wrenchScience.com/
Phone: 510.841.4748 x206
Fax: 510.841.4708
-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-
 
A

Aaron Prohaska

Well, I've gone and completely changed the way I'm trying to databind
this combobox. Now I don't get any values displayed in the drop down at
all. Can please tell me what I'm doing wrong?

private void BindObjects()
{
this.flexibilityList.DataSource = this.GetFlexibilityValues();
this.flexibilityList.ValueMember = "Text";
this.flexibilityList.DisplayMember = "Text";
this.flexibilityList.SelectedIndex =
this.flexibilityList.FindStringExact(this.measurement.Flexibility.ToString());
this.flexibilityList.DataBindings.Add("SelectedValue",
this.measurement, "Flexibility");
}

private System.Data.DataTable GetFlexibilityValues()
{
System.Data.DataTable table = new System.Data.DataTable();
DataRow dataRow;

table.Columns.Add( "Text" );

for(int i = 0; i < 10; i++)
{
dataRow = table.NewRow();
dataRow[0] = i.ToString();
}
return table;
}

Regards,

Aaron Prohaska

-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-
Wrench Science Inc.
http://www.wrenchScience.com/
Phone: 510.841.4748 x206
Fax: 510.841.4708
-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-
 

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