473,396 Members | 1,940 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

C#-APP: Problems dynamically databinding comboboxes

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!
May 8 '08 #1
0 1288

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Jon | last post by:
Hi all, I am trying to dynamically fill an array with any unique values from a field (objRS.Fields(5)) in my database with the following code below. However it errors with "The array is fixed...
3
by: Musravus | last post by:
Hi all, I have a piece of XML that looks like this, which I want to DataBind to a Repeater (the Repeater is inside a UserControl): <SECTION id="MAIN" > <SUBSECTION id="SUB1" /> <SUBSECTION...
6
by: Papa.Coen | last post by:
I've just spend a lot of time solving the following problem: I used dotNet 2.0 / Visualstudio 2005 / C# / aspx, enable viewstate is set on all controls. I have 2 listboxes; the left contains items...
0
by: Evan | last post by:
I have a textbox bound to a column in a DataTable using DataBinding. I have a Next button and in the Click Event it moves the current position of the CurrencyManager to the next position. The...
0
by: Kevin | last post by:
Hi my name is Kevin I am currently working on a Asp 2.0 project and im having some ObjectDataSource Problems The thing is i have a Class called User and a Bussiness Logic Layer FcUser with...
1
by: esakal | last post by:
Hello, I have a very strange problem which involve databinding in winform c#.net 2 . I have a user control which holds textbox inside. the user control has property which reflect the...
3
by: Mark Denardo | last post by:
I'm trying to dynamically create and add controls to a web page: Label obj1 = new Label(); DropDownList obj2 = new DropDownList(); Controls.Add(obj1); Controls.Add(obj2); But I get the...
3
by: Brennan Finighan | last post by:
Hello I am using VS 2005 with .net 2 with C#. I have a form with a panel in which I am dynamically creating combo boxes. They are all using the same data source.The reason they are dynamically...
3
by: =?Utf-8?B?VmFuZXNzYQ==?= | last post by:
Hi all! I have a tab control with 2 tabs. All tabs have fields that are databinding to a unique binding source. The problem is that if I don't access the second tab, it didn't work. After access...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.