Get a DataGridView Column Value

Good Day:

I am using VB.NET 2005 with the DataGridView control called grdSODetail.  After the user enters a value in the Cust P/N grdSODetail column; I would like to retrieve the Cust P/N value using one of the DataGridViewCell events. The following code does not work because the CellValidating event is not able to set the Cust P/N column value in time to retrieve the value and returns the following error:
Null Reference; Object Reference Not Set to an Instance of an Object.

My code is as follows:
Private Sub grdSODetail_CellValidating(ByVal sender As Object, _
                ByVal e As DataGridViewCellValidatingEventArgs) _
                Handles grdSODetail.CellValidating

If String.IsNullOrEmpty(e.FormattedValue.ToString()) = False Then
            sCustPN = grdSODetail.Rows(iRow).Cells("Cust P/N").Value.ToString
                    End If
    End Sub

Can anyone suggest a DataGridView event I can use to run my code and retrieve the value of the Cust P/N column value?  Or perhaps something else to make this work?

Thank You,
Denise
DeniseGoodheartAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jorge PaulinoIT Pro/DeveloperCommented:
Hi DeniseGoodheart,

You can use the cell endedit:

Private Sub DataGridView1_CellEndEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit
        MsgBox(DataGridView1(e.ColumnIndex, e.RowIndex).Value)
End Sub


jpaulino
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jorge PaulinoIT Pro/DeveloperCommented:
you can validate this way

        If DataGridView1(e.ColumnIndex, e.RowIndex).Value = "" Then
            MsgBox("Not valid!")
        Else
            MsgBox(DataGridView1(e.ColumnIndex, e.RowIndex).Value)
        End If
0
DeniseGoodheartAuthor Commented:
Many thanks JPaulino.

Cheers,
Denise
0
Jorge PaulinoIT Pro/DeveloperCommented:
Glad I could help Denise
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.