Click here to Skip to main content
Rate this: bad
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 22:37pm
Edited 7-Aug-12 23:49pm
aspnet_regiis at 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
0 OriginalGriff 375
1 Richard Deeming 240
2 _Amy 205
3 CHill60 195
4 Nirav Prabtani 178
0 OriginalGriff 8,104
1 Sergey Alexandrovich Kryukov 7,045
2 Maciej Los 4,039
3 Peter Leow 3,738
4 CHill60 2,912

Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 8 Aug 2012
Copyright © CodeProject, 1999-2014
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