473,777 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C#-APP: Problems dynamically databinding comboboxes

3 New Member
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 = ((DynamicCharac teristic)cashfl owchars[i]).getDataRow();
//instantiate new combobox
ComboBox cboBox_char = new ComboBox();
//set name
cboBox_char.Nam e = ((DynamicCharac teristic)cashfl owchars[i]).getCharID().T oString();
//get options for combobox
ArrayList options = ((DynamicCharac teristic)cashfl owchars[i]).getOptions();

//create bindinglist from array
BindingList<PDR eportDataSet.Ch aracteristicLis tItemRow> bl = new BindingList<PDR eportDataSet.Ch aracteristicLis tItemRow>();

//populte bindinglist
for (int j = 0; j < options.Count; j++)
{
bl.Add((PDRepor tDataSet.Charac teristicListIte mRow)options[j]);
}

//set members and datasource
cboBox_char.Dis playMember = "ShortName" ;
cboBox_char.Val ueMember = "Characteristic ListItemID";
cboBox_char.Dat aSource = bl;

//set databinding
cboBox_char.Dat aBindings.Add(" SelectedValue", drv_dataRow, "Characteristic Value");

//set current item in combobox
int index = cboBox_char.Fin dStringExact(xm lRenderingClass .getListItemNam e(Int32.Parse(( (DynamicCharact eristic)cashflo wchars[i]).getVal())));
cboBox_char.Sel ectedIndex = index;
//add event handling
cboBox_char.Sel ectedIndexChang ed += new System.EventHan dler(this.chara cteristicComboB ox_SelectedInde xChanged);
//format combobox
cboBox_char.Dro pDownStyle = ComboBoxStyle.D ropDownList;
cboBox_char.Wid th = 200;
//add control to tablelayoutpane l
tablepanel.Cont rols.Add(cboBox _char, 1, i);


Any help would be much appreciated!
May 8 '08 #1
0 1314

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

Similar topics

2
2842
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 or temporarily blocked" for the line "REDIM PRESERVE UserArray(Arraycount+1)". I can't seem to get around this. Any suggestions? Many thanks. Dim p Dim UserArray(0) ' Max number of users
3
2611
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 id="SUB2" /> <SUBSECTION id="SUB3" /> </SECTION>
6
3659
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 that can be (dynamically) added to the right box. Adding the first item went fine, it shows up in the right box. Adding the second item resulted in losing _every_ control following the right box. 'View source' reveiled that the rendering of the...
0
1072
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 CurrencyManager is moving to the next position but the textbox is not being updated with the value of the next row, it stays at the value of the first row. // Initialization string stockItemSelect = "SELECT stock_number "FROM po_stock_item ";...
0
1477
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 the functions GetAllUsers, GetUserByID(int) and a InsertUser(BoUser as User), the both return a generic list of User objects, the insert method sends a User object from my UI provided by the ObjectDatasource
1
2425
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 inner textbox text
3
5497
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 following error when the DDL is added (but not the Label): "Control 'ctl07' of type 'DropDownList' must be placed inside a form tag
3
1407
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 created is because the program does not how many are required. When I change the selected index for any one of the comboboxes they all change to the same selected index. Any ideas ??. I have tried creating the event as a delegete inside the method...
3
1090
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 it, all works fine. For example, I have the following tabs: Tab 1 nameTextBox
0
9628
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9464
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10122
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9923
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8954
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7471
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5497
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3627
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2860
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.