I have written a class to show a form that contains a datagridview. The class connects to a database, creates a datatable and uses that as the source for the datagridview.
I then add the datagridview to the form using Controls.Add().
When the form is displayed using ShowDialog(), the columns are there as expected.
However, if I try to edit the datagridview columns (width, etc) prior to ShowDialog(), I get an error. If I count the rows in debugging, they are 0. However, if I step into the ShowDialog() action (bypassing anything that tries to edit the columns), the form appears with all the columns.
I'm wondering where I need to edit the datagridview columns before they appear to the user.
Any help on this would be much appreciated.