I'm attempting to return all column names from a DataGridView.
I tried:
Dim ch As String = DataGridView1.Columns(DataGridView1.CurrentCell.ColumnIndex).Name()
But this only returns the currently selected cell. I think it can be done with a For Each Loop but I don't know the syntax for looping through each DataGridView Column name.
***************Update
For anyone interested this is what I came up with for adding each column name to a ComboBox:
I tried:
Dim ch As String = DataGridView1.Columns(DataGridView1.CurrentCell.ColumnIndex).Name()
But this only returns the currently selected cell. I think it can be done with a For Each Loop but I don't know the syntax for looping through each DataGridView Column name.
***************Update
For anyone interested this is what I came up with for adding each column name to a ComboBox:
VB.NET:
For Each cn As DataGridViewColumn In DataGridView1.Columns
Me.RefCombo.Items.Add(cn.Name)
Next
Last edited: