Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8907689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:58:52+00:00 2026-06-15T02:58:52+00:00

I have a dictionary that has as its keys a three letter country code,

  • 0

I have a dictionary that has as its keys a three letter country code, and as its values the name of the country.

Dictionary<string, string> CountryList=new Dictionary<string, string>();

I also have a DataGridView and a DataTable. What I’d like to do is to create a DataGridViewComboBoxColumn for certain columns in my DataTable-columns that display country information. So, for example, one of my columns in my DataTable is called Country, and I’d like for that column to have a drop down combo box that displays the name of the country, and that when selected, populates the cell in the DataTable with the key from the dictionary (the three letter code). However, I’m totally stumped as to how to do this. Do I have to set the DataSource to the keys, and the DisplayMember to the values? I tried that, and got an error:

DataGridViewComboBoxColumn buildCountries = new DataGridViewComboBoxColumn();
buildCountries.HeaderText = "List of Countries";
buildCountries.DataSource = CountryList.Keys.ToString();
buildCountries.DisplayMember = CountryList.Values.ToString();

Complex DataBinding accepts as a data source either an IList or an IListSource

I’m not sure how to go about doing this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T02:58:53+00:00Added an answer on June 15, 2026 at 2:58 am

    I’m not 100% positive but I think you won’t be able to accomplish this the way you were trying. I know that this may be considered as heavy artillery but you could create a DataTable out of the Dictionary and do a DataBinding on it.

    DataGridViewComboBoxColumn buildCountries = new DataGridViewComboBoxColumn();
    buildCountries.HeaderText = "List of Countries";
    DataTable dataTable = new DataTable();
    dataTable.Columns.Add("Keys");
    dataTable.Columns.Add("Values");
    KeyValuePair<string, string> [] array = CountryList.ToArray();
    foreach(KeyValuePair<string, string> kvp in array)
    {
            dataTable.Rows.Add(kvp.Key, kvp.Value);
    }
    buildCountries.DataSource = dataTable;
    buildCountries.DisplayMember = "Values";
    buildCountries.ValueMember = "Keys";
    dataGridView1.Columns.Add(buildCountries);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a listbox that has its ItemsSource set to a Dictionary(Of String, ColumnMetadata)
I have a dictionary that has keys associated with lists. mydict = {'fruits': ['banana',
I have an NSArray storing NSDictionaries. Each dictionary has two keys; a name and
I have constructed two dictionary that contains histogram values of images. Each dictionary has
I have a javascript dictionary object which has a pre-set keys that are defaulted
I have a Dictionary object that is formed using a double as its key.
I have a dictionary where I want to alphabetically sort the keys that have
I have a document which has been sloppily authored. It's a dictionary that contains
I have Dictionary<string,string> keyValList; its data looks like: <{1} , TEXT NUMBER 1> <{2}
I have a class that implements INotifyPropertyChanged and also has its own concept of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.