title: Using a list as a data source for DataGridView
body: <p>I've extracted the setting names and their respective values out of a configuration file into an ordered dictionary. The dictionary contains keys and values which are of the ICollection class. I want to bind that data and display it in a DataGridView. I've tried copying the strings to arrays and displaying those arrays, but when I ran the program the columns were blank and it did not seem to be binded at all.</p>
  
  <p>I've also attempted to set the DataGridView source directly to one the ordered dictionary collections (keys or values), but that also did not result in anything I wanted; the columns were still blank. However, a third column is made with the column name as "length" and displays the lengths of the entries in the ICollection. But needless to say I do not want the lengths, I want the entries themselves.</p>
  
  <p>Here is the code that I am using for this question: Upon the loading of the form, I load the configuration file and a private member called m_Settings has all the key-value pairs. Then I create a list and add the keys and the values separately. After setting the binding source to 'data', I run the program and both columns I added are both blank. </p>
  
  <pre><code>    private void Form4_Load(object sender, EventArgs e)
      {
          loadconfigfile(Properties.Settings.Default.Config);
          List&lt;Object&gt; data = new List&lt;Object&gt;();
          data.Add(m_Settings.Keys);
          data.Add(m_Settings.Values);
          bindingSource1.DataSource = data;
          dataGridView1.DataSource = bindingSource1;
          dataGridView1.Refresh();
      }
  </code></pre>
  
  <p>Any ideas as to how I could get the ordered dictionary and display the entries in two columns labelled "Settings" and "Values"? I believe that lists were compatible DataSources for DataGridViews, but now I'm starting to second-guess myself.</p>
  
  <p>Any help or direction is greatly appreciated! I'll be happy to provide more information if needed.</p>
  
  <p>Thanks!</p>
  
  <p><strong>EDIT</strong>:</p>
  
  <p>Here is the revised code with the implemented myStruct class:</p>
  
  <pre><code>    List&lt;myStruct&gt; list = new List&lt;myStruct&gt;();
      for(int index = 0; index &lt; m_Settings.Count; index++)
      {
          myStruct pair = new myStruct(keys[index], values[index].ToString());
          list.Add(pair);
      }
  
      public class myStruct
      {
          private string Key { get; set; }
          private string Value { get; set; }
  
          public myStruct(string key, string value)
          {
              Key = key;
              Value = value;
          }
      }
  </code></pre>
  
  <p>However, when I set the binding DataDource to list, nothing appears on the DataGridView, it's simply empty. Anyone know why?</p>