Trapping exception in rowchanging event.

Posted on 2006-04-13
Last Modified: 2008-01-09
Hello, I am doing some validation on the rowchanging event of my datagrid which checks to see if certian fields are filled in.  If one of the columns in null I throw an exception to cancel the editing.  Is there a way to trap this exception and then display one of my own message boxes?  I tried using try..catch to trap it and then put my messagebox in the Catch but when doing this I get the error: "error when committing the row to the original data source".  Is there a way to get this to work?  My code is below.


            'check to make sure all required fields are populated
            If e.Row.Item("TransDate") Is DBNull.Value Then
                e.Row.SetColumnError("TransDate", "Date is a required field")
                Exit Sub
            ElseIf e.Row.Item("TransactionType") Is DBNull.Value Then
                e.Row.SetColumnError("TransactionType", "Activity is a required field")
                    Throw New Exception("Activity is a required field.")
                Catch ex As Exception
                End Try
                Exit Sub
            End If
Question by:crussell96
    1 Comment
    LVL 2

    Accepted Solution

    if e is a datatable, you need to specify an actual row index when you access a field in the column. You can loop through your table to look at each row like this:

    Dim dr as datarow
    for each dr in e.rows
     if dr.item("TransDate") is dbnull then
     end if

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
    Introduction When many people think of the WebBrowser ( control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    733 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

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now