Resolved Get all column names from DataGridView

Fedaykin

Active member
Joined
Mar 20, 2013
Messages
30
Programming Experience
Beginner
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:

VB.NET:
        For Each cn As DataGridViewColumn In DataGridView1.Columns
            Me.RefCombo.Items.Add(cn.Name)
        Next
 
Last edited:
Back
Top