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("P rojectId") .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?
--------------------------
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
Continue For
End If
fsNewFieldNm = .Rows.Item(fnCtr).Cells("P
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?
Question is ProjectId The exact Name Of The Column you are pulling data from?
Use FindControl
like
Rows.Item(fnCtr).FindContr ol("Projec tId").Valu e
like
Rows.Item(fnCtr).FindContr
ASKER
NBIT -
Yes, ProjectId is the exact name of the column.
princeatapi -
'FindControl' is not a member of datagridviewrow
Yes, ProjectId is the exact name of the column.
princeatapi -
'FindControl' is not a member of datagridviewrow
.Rows.Item(fnCtr).Cells(.C olumns("Pr ojectId"). Index).Val ue
Try The Index specifically.
Try The Index specifically.
ASKER
error:
NullReferenceException was unhandled.
NullReferenceException was unhandled.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
You were correct. There was a typo in the column name.
Thanks!
Thanks!