Hi all,
I'm having trouble with a datagridview. I use a datatable to fill it and no matter if I set autogenerate columns true or false, I still get no columns in the datagridview datasource, if there are no rows in the datatable.
The funny thing is that in another form, I use the exactly (or so I think) same code for another datagridview and there it works fine.
(The reason why I need to fill the datagridview's datasource is that I want the columns to show even if there are no rows of data.)
Here's the code:
The problem is that the datasource doesn't get populated (its column count says 0 even if the datatable column count says 9), and so, the program crashes at dgvMeddelanden.Columns(COL_RUBRIK)... as there are no columns present. It's really strange!
Please help if you can,
Pettrer
I'm having trouble with a datagridview. I use a datatable to fill it and no matter if I set autogenerate columns true or false, I still get no columns in the datagridview datasource, if there are no rows in the datatable.
The funny thing is that in another form, I use the exactly (or so I think) same code for another datagridview and there it works fine.
(The reason why I need to fill the datagridview's datasource is that I want the columns to show even if there are no rows of data.)
Here's the code:
VB.NET:
Dim params As String() = {"@MyID", varde}
Dim dtDGV As DataTable = GetSqlTable("My_storedproc", params)
dgvMeddelanden.DataSource = dtDGV
dgvMeddelanden.Columns(COL_RUBRIK).AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
dgvMeddelanden.Columns(COL_RUBRIK).HeaderCell.ToolTipText = "My message."
The problem is that the datasource doesn't get populated (its column count says 0 even if the datatable column count says 9), and so, the program crashes at dgvMeddelanden.Columns(COL_RUBRIK)... as there are no columns present. It's really strange!
Please help if you can,
Pettrer
Last edited: