title: Set columns width in a datagrid using Compact Framework
body: <p>I'm trying to set the width of the columns in my datagrid. I use Compact Framework 2.0 and C#</p>
  
  <p>I tried this but it gives me an "out of bonds" error message:</p>
  
  <pre><code>foreach (DataGridColumnStyle vColumnStyle in dataGrid1.TableStyles[0].GridColumnStyles)
  {
      vColumnStyle.Width = 100;
  }
  </code></pre>
  
  <p>Here is the code for filling my datagrid with the datatable (only fails when I try to set the columns width):</p>
  
  <pre><code>void FillData()
  {
      // 1
      // Open connection
      string conString = "Data Source=\\Program Files\\smartdeviceproject2\\repartocrack.sdf";
      using (SqlCeConnection c = new SqlCeConnection(conString))
      {
          c.Open();
          // 2
          // Create new DataAdapter
          using (SqlCeDataAdapter a = new SqlCeDataAdapter(
          "SELECT codbultocomp, nombre, estado FROM envios INNER JOIN tiendas ON envios.codigodestino = tiendas.codigodestino", c))
          {
              // 3
              // Use DataAdapter to fill DataTable
              DataTable t = new DataTable();
              a.Fill(t);
              // 4
              // Render data onto the screen
              foreach (DataGridColumnStyle vColumnStyle in dataGrid1.TableStyles[0].GridColumnStyles)
              {
                  vColumnStyle.Width = 100;
              }
              dataGrid1.DataSource = t;
          }
      }
  }
  </code></pre>