Click here to Skip to main content
13,408,530 members (43,513 online)
Rate this:
Please Sign up or sign in to 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
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.
The below code for bind statename at combobox1_selectedIndexChandged event
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 7-Aug-12 23:37pm
Updated 8-Aug-12 0:49am
aspnet_regiis 8-Aug-12 5:09am
incomplete information ..needs to see the complete code
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Have a look on Windows Forms Databound Combobox - The Easy Way[^].
This might be useful for you.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.180221.1 | Last Updated 8 Aug 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100