Hi,
I am creating an application which dynamically creates forms depending on the information held in a dataset (which also includes the data the application itself uses). As part of dynamically creating these forms, I need to bind controls back to their underlying tables. This has been successful with textboxes, but I am having a lot of difficulty with comboboxes. Setting the datasource to the bindinglist seems to be ok, but I am having trouble setting the selectedindex/item/value (I believe it is item I need to use to bind to the underlying object) when I initialise the form, FindStringExact doesn't seem to be able to find the item which throws an exception.
Here is the part of the code which generates comboboxes:
//datarowview for the particular piece of information
DataRowView drv_dataRow = ((DynamicCharacteristic)cashflowchars[i]).getDataRow();
//instantiate new combobox
ComboBox cboBox_char = new ComboBox();
//set name
cboBox_char.Name = ((DynamicCharacteristic)cashflowchars[i]).getCharID().ToString();
//get options for combobox
ArrayList options = ((DynamicCharacteristic)cashflowchars[i]).getOptions();
//create bindinglist from array
BindingList<PDReportDataSet.CharacteristicListItem Row> bl = new BindingList<PDReportDataSet.CharacteristicListItem Row>();
//populte bindinglist
for (int j = 0; j < options.Count; j++)
{
bl.Add((PDReportDataSet.CharacteristicListItemRow) options[j]);
}
//set members and datasource
cboBox_char.DisplayMember = "ShortName";
cboBox_char.ValueMember = "CharacteristicListItemID";
cboBox_char.DataSource = bl;
//set databinding
cboBox_char.DataBindings.Add("SelectedValue", drv_dataRow, "CharacteristicValue");
//set current item in combobox
int index = cboBox_char.FindStringExact(xmlRenderingClass.getL istItemName(Int32.Parse(((DynamicCharacteristic)ca shflowchars[i]).getVal())));
cboBox_char.SelectedIndex = index;
//add event handling
cboBox_char.SelectedIndexChanged += new System.EventHandler(this.characteristicComboBox_Se lectedIndexChanged);
//format combobox
cboBox_char.DropDownStyle = ComboBoxStyle.DropDownList;
cboBox_char.Width = 200;
//add control to tablelayoutpanel
tablepanel.Controls.Add(cboBox_char, 1, i);
Any help would be much appreciated!