Vb.net cannot change Datagridview column index
I am trying to increase the width of a last dummy column in a datagridview so that I display certain rows after a button click.
The DGV is bigger that the screen so it scrolls, also the forth column is frozen.
I am using the following code :
Code:
Private Sub ButtonHierdieWeek_Click(sender As Object, e As EventArgs) Handles ButtonHierdieWeek.Click
Dim BufferKolomWydte As Integer = 0
For i As Integer = 23 To 32 Step 1
SkeduleringDataGridView.Columns(i).Visible = False
BufferKolomWydte = BufferKolomWydte + SkeduleringDataGridView.Columns(i).Width
Next
BufferKolomWydte = BufferKolomWydte + SkeduleringDataGridView.Columns(12).Width + SkeduleringDataGridView.Columns(13).Width
SkeduleringDataGridView.FirstDisplayedScrollingColumnIndex = 15
SkeduleringDataGridView.Columns(33).AutoSizeMode = DataGridViewAutoSizeColumnMode.NotSet
SkeduleringDataGridView.Columns(33).Width = BufferKolomWydte
End Sub
However the column width does not change. I have set the DataGridViewAutoSizeColumnMode to NotSet above.
Is there another setting that I am missing?
Re: Vb.net cannot change Datagridview column index
Hi Gideon,
This might help.
You might like to note that
Code:
For i As Integer = 23 To 32 Step 1
can be written as The index will always be an integer and the step is 1 by default so is only needed if the step is to be something other than 1, (-1, 2, 5 etc.)
Poppa