Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi friends.
I want to bind country,state,city to combobox.what i have done is country name has been bound to combobox1 at the page_load event. The below code for binding country on the page load event
stage(1)
int i = 3;
            DataTable dt = ibl2.combo1(i);
            countrycombo.DataSource = dt;
            countrycombo.DisplayMember =Convert.ToString( dt.Columns["Country_name"]);
            countrycombo.ValueMember = Convert.ToString(dt.Columns["Country_id"]);

country name successfully bound to contrycombobox.
stage(2)
The below code for bind statename at combobox1_selectedIndexChandged event
C#
private void countrycombo_SelectedIndexChanged(object sender, EventArgs e)
       {

           string countyname = Convert.ToString( countrycombo.SelectedItem);
           DataTable ds = ibl2.statecombo(countyname);
           statecombo.DataSource = ds;
           if (ds != null)
           {
               statecombo.DisplayMember = Convert.ToString(ds.Columns["State_name"]);
               statecombo.ValueMember = Convert.ToString(ds.Columns["State_id"]);
           }



The problem occurrs on the second stage.Binding the state name to combobox2(statecombo) based on the country name.
The problem is when binding the statename to combobox2 at the combobox1_selectedIndexchanged event it take null value from country name.when i trace this process using f11 key, combox1_selectedItem event occur after the code
countrycombo.DataSource = dt;
in the page load itself so that it doesnt take any value from country combo box. what i need is this event should be occur after when i select the name of the country. what can i do.
Posted
Updated 7-Aug-12 23:49pm
v2
Comments
bbirajdar 8-Aug-12 5:09am    
incomplete information ..needs to see the complete code

In the change event, check for a null selection and ignore it. Alternatively, do not add the delegate handler until a later point in your program, after the form has been loaded.
 
Share this answer
 
Have a look on Windows Forms Databound Combobox - The Easy Way[^].
This might be useful for you.
 
Share this answer
 

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