DataGridView AutoSizeColumnsMode Fill Problem
Hi
I'm having a problem when trying to add a column to a datagridview in autosizecolumnsmode set to fill.
After some tests i realize that i can't insert a column to the datagridview. The autosizecolumnsmode it's set at design time.
vb.net Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim sqlCon As New SqlConnection("******")
Dim sqlPFs As New SqlCommand("spTest", sqlCon)
Dim adapterPFs As New SqlDataAdapter(sqlPFs)
Dim dtPFs As New DataTable
Dim bs As New BindingSource
sqlPFs.CommandType = CommandType.StoredProcedure
adapterPFs.Fill(dtPFs)
bs.DataSource = dtPFs
DataGridView1.DataSource = bs
If DataGridView1.Columns("Info") Is Nothing Then
Dim colInfo As New DataGridViewImageColumn
With colInfo
.Visible = True
.Name = "Info"
.Frozen = True
.ImageLayout = DataGridViewImageCellLayout.Zoom
.FillWeight = 50
End With
DataGridView1.Columns.Insert(0, colInfo) ////////////WHEN SET TO FILL IT JUMPS OUT HERE
Else
DataGridView1.Columns("Info").Visible = True
End If
End Sub
Re: DataGridView AutoSizeColumnsMode Fill Problem
I haven't tried this, but i'd turn off autosizecolumnsmode, insert a column, then turn autosizecolumnsmode back on...
Re: DataGridView AutoSizeColumnsMode Fill Problem
I've just noticed your dgv is bound. did you try inserting the column into the datatable?
Re: DataGridView AutoSizeColumnsMode Fill Problem
I already tried some combinations:
1 - Design to NONE, in the end of the code changed to FILL, columns doesn't adapt at all...
2 - Design to FILL, before adding the column set to NONE, after finishing set to FILL, the columns in the datatable fill the space but the new column doesn't... scrollbar visible.
3 - Design to FILL, before adding the column set to NONE, in the column changed the AutoSizeMode to fill, when the code reaches the addding part it jumps out...
By adding the columns to the datatable directly, should work.
But sometimes by some reason the columns must be added directly to the datagridview without messing with the datatable... and in those situations why we can't add columns when set the auto size columns mode to fill.
Some kind of issue with this combination? Datatable + Fill + Add Column?
Thanks