You are not initilazing any column, you need to dim it as a NEW Datagridviewcolumn.
Also as @marlan pointet, you are creating arrays of columns, you don't need thoose.
And in my opinion a for
is better here than a do while, but that's just matter of opinion.
Dim varCount As Integer = 0
Dim I As Integer = 1
Try
Do While varCount < 1
Dim column As new DataGridViewColumn
With column
.HeaderText = "Details"
.Name = "Details"
' Use the Text property for the button text for all cells rather
' than using each cell's value as the text for its own button.
End With
DataGridView1.Columns.Insert(0, column)
I = I + 1
varCount = varCount + 1
Loop
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
With for:
Dim I As Integer = 1
Try
For index = 1 To 10 'How many do you want?
Dim column As new DataGridViewColumn
With column
.HeaderText = "Details"
.Name = "Details"
' Use the Text property for the button text for all cells rather
' than using each cell's value as the text for its own button.
End With
DataGridView1.Columns.Insert(0, column)
Next
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
EDIT
As @beldi-anouar pointet (Not my day today -.-) you cannot create more than one column with the same name.
You could make an array of strings for the names and another for the headers.
Dim names = {"name1", "name2"}
Dim headers = {"head1", "head2"}
And then asign them:
With column
.HeaderText = headers(index)
.Name = names(index)
End With
Thats for the for
, not the do while. In the do while just substitude index
with varCount