c# windows forms
how add countries names to combobox and their respective states in another combobox in windowsforms
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Guest UserPosted Jul 24, 2014, 3:55 AM
I can give high level algorithm to do so, one way to achieve using JSON
# Create a data structure, in JSON, e.g.,
var mapping ={"India":["New Delhi","Rajasthan","Maharashtra", "Telangana", "Tamil Nadu"], "USA":["Washington","New York","Florida"]}";
now use Newtonsoft.JSON to parse JSON structure and now attach to combo box with key-value pair, say
comboboxCountry = JSON.Item(1);
Now at change of comboboxCountry you can populate the second one:
comboxboxCountry_change(item)
{
var item2=JSON.Item(1).Where(x=>x==comboboxCountry.Text);
comboxBoxState.bind=item2;
}
Hope this helps!
twitter @sumitjolly