.NET datagridview data selection

I am sure this is straight forward but I am missing something.  Have a datagridview with many columns defined.  This function is called to step thru only the selected rows:
-----------------------------------------------------------------
Function fCopyEntries(ByVal foInDataGridView As DataGridView, ByVal fsInType As String) As Boolean

        Dim fnMaxRows As Long
        Dim fnCtr As Integer
        Dim fsNewFieldNm As String

        With foInDataGridView
            fnMaxRows = .RowCount - 1

            For fnCtr = 0 To fnMaxRows
                If .Rows.Item(fnCtr).Selected = False Then
                    Continue For
                End If

                fsNewFieldNm = .Rows.Item(fnCtr).Cells("ProjectId").Value
                MsgBox(fsNewFieldNm)
            Next
        End With

        If fnMaxRows >= 0 Then
            Return True
        Else
            Return False
        End If

End Function

-----------------------------------------------------------------
I get the error "column ProjectId not found"

What am I doing wrong?
kkbenjAsked:
Who is Participating?
 
Naithan ArroyoConnect With a Mentor Commented:
Ive tested it in many ways  the only discrepancy i can see is if the column is named wrongly , the Name is not the header text. or since its a function make sure you called it with the correct datagrid (if you have more than one)  
0
 
Naithan ArroyoCommented:
Question is  ProjectId The exact Name Of The Column you  are pulling data from?
0
 
princeatapiCommented:
Use FindControl
like
Rows.Item(fnCtr).FindControl("ProjectId").Value
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
kkbenjAuthor Commented:
NBIT -
Yes, ProjectId is the exact name of the column.

princeatapi -
'FindControl' is not a member of datagridviewrow
0
 
Naithan ArroyoCommented:
.Rows.Item(fnCtr).Cells(.Columns("ProjectId").Index).Value
Try The Index specifically.
0
 
kkbenjAuthor Commented:
error:
NullReferenceException was unhandled.

0
 
kkbenjAuthor Commented:
You were correct.  There was a typo in the column name.

Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.