开发者

DataGridView columns still automatically created even with AutoGenerateColumns = False

开发者 https://www.devze.com 2023-01-15 06:02 出处:网络
I have a DataGridView and have the AutoGenerateColumns property set to false, but the when I 开发者_Go百科build my project the columns are Auto Generated.

I have a DataGridView and have the AutoGenerateColumns property set to false, but the when I 开发者_Go百科build my project the columns are Auto Generated.

I can see the property set to false in the Designer.vb code for the Form.

I've had this problem before and I'm not sure how to fix it.

Any advise would be greatly appreciated.

Thanks.


I know this is an old question, but maybe it helps someone who searches for the same issue:

I ran in this problem today. It is important to set the 'AutoGenerateColumns'-property before you set the DataSource, otherwise the columns get generated before you told the DataGridView not to do so:

DataGridView1.AutoGenerateColumns = False
DataGridView1.DataSource = mySource


I have re-added the control and it seems to be working for the time being. I believe something became corrupted, causing the problem. As I mentioned in the question I've had this happen before. If anyone else has a problem like this it would be great if you could provide some details.


I have found that if you're trying to setup columns during load of the form, then you expierence weird issues like this. Instead, just before populating the grid, I check to see if there are columns defined and if not, then I go ahead and configure the columns at that point. This is working consistenly for me -- when populating the columns, I set the property to auto add columns = false first thing:

    Private Sub Populate_dgvQuoteSelection(status_id As Int32)
    dgvQuoteSelection.DataBindings.Clear()
    If dgvQuoteSelection.Columns.Count = 0 Then
        Setup_dgvQuoteSelection()
    End If
    Try
        dgvQuoteSelection.DataSource = DataService.Quote_HeaderDataService.Quote_GetListView_byStatus(status_id)
    Catch ex As Exception
        MessageBox.Show(String.Format("An error occured while trying to get the grid data: {0}", ex.Message), "Error populating grid", MessageBoxButtons.OK, MessageBoxIcon.Error)
    End Try
End Sub
0

精彩评论

暂无评论...
验证码 换一张
取 消