C# windows forms
how add countries names to combobox and their respective states in another combobox in windowsforms
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Guest UserRank #258 · 9.8K pointsPosted Jul 23, 2014, 11:55 PM EDT
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