?
Solved

.NET datagridview data selection

Posted on 2010-01-06
7
Medium Priority
?
213 Views
Last Modified: 2013-11-26
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?
0
Comment
Question by:kkbenj
  • 3
  • 3
7 Comments
 
LVL 5

Expert Comment

by:Naithan Arroyo
ID: 26192542
Question is  ProjectId The exact Name Of The Column you  are pulling data from?
0
 
LVL 11

Expert Comment

by:princeatapi
ID: 26192564
Use FindControl
like
Rows.Item(fnCtr).FindControl("ProjectId").Value
0
 

Author Comment

by:kkbenj
ID: 26192612
NBIT -
Yes, ProjectId is the exact name of the column.

princeatapi -
'FindControl' is not a member of datagridviewrow
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 5

Expert Comment

by:Naithan Arroyo
ID: 26192796
.Rows.Item(fnCtr).Cells(.Columns("ProjectId").Index).Value
Try The Index specifically.
0
 

Author Comment

by:kkbenj
ID: 26192844
error:
NullReferenceException was unhandled.

0
 
LVL 5

Accepted Solution

by:
Naithan Arroyo earned 2000 total points
ID: 26192896
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
 

Author Closing Comment

by:kkbenj
ID: 31673595
You were correct.  There was a typo in the column name.

Thanks!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

755 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question