title: How do I use my own header names in a DataGridView filled by database?
body: <p>I'm trying to use my own headers text in a DataGridView which is filled automatically from database. I've tried <code>dataGridView1.AutoGenerateColumns = false</code> then do something like to create the columns:</p>
  
  <pre><code>    void createSearchResultHeader()
      {
          foreach(var prop in typeof(DB.Message).GetProperties())
          {
              var display =
                 typeof(DB.Message)
                 .GetProperty(prop.Name)
                 .GetCustomAttributes(typeof(System.ComponentModel.DisplayNameAttribute), inherit: false)
                 .FirstOrDefault() as System.ComponentModel.DisplayNameAttribute;
              DataGridViewColumn col = new DataGridViewTextBoxColumn();
              col.HeaderText = display.DisplayName;
              dataGridView1.Columns.Add(col);
          }
      }
  </code></pre>
  
  <p>then load the results with:</p>
  
  <pre><code>            using (var conn = createConnection())
              using (var da = new SQLiteDataAdapter(createCommand(conn)))
              using (var dt = new DataSet())
              {
                  dt.Locale = System.Globalization.CultureInfo.InvariantCulture;
                  da.Fill(dt);
                  dg.DataSource = dt.Tables[0].DefaultView;
              }
  </code></pre>
  
  <p>The issue is, with <code>dataGridView1.AutoGenerateColumns = false</code> the columns are created (I call <code>createSearchResultHeader()</code> on Form's load) but the result from database are empty but if I change <code>dataGridView1.AutoGenerateColumns = true</code> the results from database are loaded successfully but it add its own columns rather use the ones created by <code>createSearchResultHeader()</code>. How can I fix that?</p>