Skip to content

C# windows forms

Gopikrishna Medarametla

Asked Jul 23, 2014, 10:45 PM EDT1 answer
Share
LinkedInX
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.

  • 0
    it's common problem to solve and there could be multiple ways to achieve this

    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
    0