title: resizing a form according to the size of the datagridview that it contains
body: <p>my datagridview is connected to a data source: </p>
  
  <pre><code>this.dataGridView1.DataSource = mydatatable;
  </code></pre>
  
  <p>I want to present this data to the user. If it has more than X lines then it will have a vertical scrollbar. </p>
  
  <p>Placing it in a form does not look good, because the size of the form can be bigger than  the size of the datatable. I tried to manually resize the form according to the size of the datagridview like this:</p>
  
  <pre><code>this.Size = dataGridView1.Size;
  </code></pre>
  
  <p>but it does not work (if the datagridview is smaller, it does not make the form smaller. If it is bigger than it covers some of it). Perhaps there is a way to present the table without going through a form ? or is there a way to resize it correctly ?</p>
  
  <p>I have tried the following (in response to an answer):</p>
  
  <pre><code>this.dataGridView1.DataSource = competingCourses; 
  this.dataGridView1.RightToLeft = RightToLeft.Yes;
  this.dataGridView1.AutoSizeColumnsMode = dataGridViewAutoSizeColumnsMode.AllCells; 
  </code></pre>
  
  <p>I also have: </p>
  
  <pre><code>this.AutoSize=true; 
  this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; 
  </code></pre>
  
  <p>it still does not change the size of the containing form.</p>