.NET Programming With Me

VB.NET: How to get index of a column of a DataGridView?


Private Function GetColumnIndex(ByVal headerText)
        Dim columnIndex As Integer = 0


        For index As Integer = 0 To Me.DataGridView1.Columns.Count - 1


            If LCase(Me.DataGridView1.Columns(index).HeaderText) = LCase(headerText) Then
                 columnIndex  = index
                Exit For
            End If


        Next


        Return columnIndex 
    End Function

No comments: