Public dgvCells as New SortedList(Of String, Long)
'-- Load Sorted List when you first enter the DataGrid (Not Datagrid must have rows)
If dgvCells.Count = 0 then
Dim rowCurr as DataGridViewRow = datagridview1.currentrow
Dim strColumnName as string
Dim dgvColumn as New datagridviewcolumn
Dim i as Int16 = 0
For i = 0 to rowCurr.Cells.count -1
dgvColumn = rowCurr.Cells(i).OwningColumn
if dgvColumn.IsDataBound then
strColumnName = dgvColumn.DataPropertyName
Else
strColumnName = dgvColumn.name
End If
dgvCells.Add(strColumnName, i)
Next
End If
'-- Get the Cell Value by ColumnName
Dim rowCurrent as DataGridViewRow = datagridview1.CurrentRow
Dim intColumnIndex as integer = Cint(dgvCells("CompanyName"))
Dim strCompanyName as string = Cstr(rowCurrent.Cells(intColumnIndex).Value)