Click here to Skip to main content
16,012,468 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
<pre lang="c#"></pre>
I want to bind two data sources for same combo box user control . combo box user control will be used in two windows forms like form1 and form2.
Each form should display different values in a combo box .
can you please help me out with code .
Posted
Updated 9-Sep-11 1:02am
v3
Comments
KenBonny 9-Sep-11 2:57am    
I'm kind of confused. Have you made one form and are calling it twice and want to show different data in each call.

Code
{
Form1 frm = new Form1();

frm.ChangeDataSource(firstDataSource);
frm.Show(); // show first set of data
frm.ChangeDataSource(newDataSource); // change the data source
frm.Show(); // show second set of data
}

Or have you made two forms, which you call once each and you want to show different data in different forms.

Code
{
Form1 frm1 = new Form1();
Form2 frm2 = new Form2();

frm1.Show(); // show first set of data
frm2.Show(); // show second set of data
}
basiviji 9-Sep-11 6:52am    
sry kenBonny
ya you are confused
i want to create user control with combo box.
This User control using different forms.
now i want to display different list of items in different forms combo box user control.

this i want to do it in windows forms application using csharp.
please help me out with coomplete code.
thanks KenBonny.

You don't mean 'the same control'. You mean 'two instances of the same control class'.

If it inherits from ComboBox (or it contains a ComboBox which you can access via a property), you can use normal data binding: set the DataSource of the ComboBox to a list* of the appropriate type, a different list for each form. You can do the binding in the form's constructor (after the call to InitialiseComponent where the combos are set up, if you used the designer).

(*: or data table or database binding adapter or etc)
 
Share this answer
 
Comments
basiviji 9-Sep-11 9:05am    
thanks for your reply Bob.
am very new to csharp programming.
can you please help me with code same what your explaining in windows forms
BobJanova 9-Sep-11 12:47pm    
You need to show at least the skeleton of the user control you're trying to do this with first.
1) create a list
2) connect to what ever datasource you need and populate your list in 1
3) repeat step 2 for all datasources
4) data bind your combo box to the list in 1
 
Share this answer
 
Comments
basiviji 8-Sep-11 1:14am    
Hi Mehdi thanks for your reply
can you tel me what is 1 in step2.
i want to populate different values using same user control combo box in different windows forms.
am waiting for your reply
Mehdi Gholam 8-Sep-11 5:11am    
A generic list of the type of object you want to bind to. For example in the simplest case it might be list<string>
basiviji 9-Sep-11 2:05am    
<pre lang="c#"></pre>
I want to bind two data sources for same combo box user control . combo box user control will be used in two windows forms like form1 and form2.
Each form should display different values in a combo box .
can you please help me out with code .

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900