Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27208

VS 2008 [RESOLVED] How to get datagridview column index from column name

$
0
0
Hello,
I am trying to make function to get column index from column name of datagridview, if possible.
Without looping through "Columns" collection, of course.

In code I have such situation:
Code:

myInt = CInt(DataGridView1.Item("myColName", DataGridView1.CurrentRow.Index).Value)
Where program successfully read what is value in named column of current row in datagridview.
So I think my function should be possible but I don't know how to make it.

Code:

    Private Function GetColIndex(ByVal dgv As DataGridView, ByVal colname As String) As Integer
        Try
            Return dgv.Item(colname, dgv.CurrentRow.Index).Index
        Catch
            Return -1
        End Try
    End Function

That of course don't work at all.
Please help for getting my function to work.

Viewing all articles
Browse latest Browse all 27208

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>