title: How to dock a control inside a panel at runtime on windows forms?
body: <p>I am designing a simple user interface using winforms. In the designer I have a panel on the form and would like to add a datagridview control into the panel at runtime and set the dock property of the datagridview to 'Fill' so that it fills the panel.</p>
  
  <p>I am struggling to do this and following code is not working out for me:</p>
  
  <pre><code>Dim MyDataGridview as New DataGridView()
  MyDataGridView.Dock = DockStyle.Fill
  Me.MyPanel.Controls.Add(MyDataGridview)
  </code></pre>
  
  <p>Can anybody help point me in the right direction?</p>
  
  <p>Edit:</p>
  
  <p>Sorry for being vague - I don't get an error but the datagridview isn't visible. It gets added 'behind' the panel and so I tried using .SendToBack() and .BringToFront() methods thinking that the panel was hiding the datagridview but this doesn't seem to work either. At any rate, it seems like the datagridview is being added to the form but just not docked within the panel</p>