Link to home
Start Free TrialLog in
Avatar of kkbenj
kkbenj

asked on

.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?
Avatar of Naithan Arroyo
Naithan Arroyo
Flag of United States of America image

Question is  ProjectId The exact Name Of The Column you  are pulling data from?
Use FindControl
like
Rows.Item(fnCtr).FindControl("ProjectId").Value
Avatar of kkbenj
kkbenj

ASKER

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

princeatapi -
'FindControl' is not a member of datagridviewrow
.Rows.Item(fnCtr).Cells(.Columns("ProjectId").Index).Value
Try The Index specifically.
Avatar of kkbenj

ASKER

error:
NullReferenceException was unhandled.

ASKER CERTIFIED SOLUTION
Avatar of Naithan Arroyo
Naithan Arroyo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kkbenj

ASKER

You were correct.  There was a typo in the column name.

Thanks!