?
Solved

Trapping exception in rowchanging event.

Posted on 2006-04-13
3
Medium Priority
?
311 Views
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.

Thanks

            '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")
                clsMessages.ReguiredFieldMessageShow("Date")
                Exit Sub
            ElseIf e.Row.Item("TransactionType") Is DBNull.Value Then
                e.Row.SetColumnError("TransactionType", "Activity is a required field")
                Try
                    Throw New Exception("Activity is a required field.")
                Catch ex As Exception
                    clsMessages.ReguiredFieldMessageShow("Activity")
                End Try
                Exit Sub
            Else
                    e.Row.ClearErrors()
            End If
0
Comment
Question by:crussell96
1 Comment
 
LVL 2

Accepted Solution

by:
af4643 earned 200 total points
ID: 16453581
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
next
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

809 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