|
-
Nov 21st, 2003, 01:22 AM
#1
Thread Starter
Addicted Member
Datagrid / DataTable Query
Hi guys,
I'm having a bit of a headache with validating fields in a datagrid/table.
I am able to get the row fine and perform all the right checks.
(Using the datatable RowChanging event) I throw an exception as the documentation tells me too. (When I decide the data is invalid)
What happens however, is that .Net displays a message box saying that there is an error commiting to the row to the original datastore and do I wish to continue. (Yes/No) Both these options cancel the update.
My problem is that I do not want this messagebox being displayed to the user, but I cannot see how to stop it. I know I'm probably missing something pretty obvious Anyone want to tell me how to resolve this?
Cheers
-
Nov 21st, 2003, 03:24 AM
#2
Frenzied Member
I well remember having the same problem once in the past, but i dont remember how i resolved it. Unfortunately i dont have the project with me to check it. Would you please send the code?
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Nov 23rd, 2003, 05:16 PM
#3
Thread Starter
Addicted Member
Heres a chunk of the code.
VB Code:
Character = CurrentRow.Item(Column)
If Not(Character = "P" Or Character = "R" Or Character = "F" Or Character = " ") Then
Throw New Exception("Invalid Cell Input, Please Insert P, F, or R.")
End If
Really quite simple.
If I could somehow catch the exception from the rowchanging event then I could customise the output to the user.
-
Nov 23rd, 2003, 06:46 PM
#4
Frenzied Member
Where is this piece of code placed? Why can't you catch the exception from the rowchanging event?
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Nov 23rd, 2003, 07:34 PM
#5
Thread Starter
Addicted Member
The piece of code is placed inside the row changing event.
If I catch the exception inside the rowchanging event won't the edit still go thru when it shouldn't?
-
Nov 23rd, 2003, 10:19 PM
#6
Frenzied Member
Try using the RowChanged event and use RejectChanges method instead of throwing exception. That messagebox comes up because you can not cancel changes in rowchanging event.
However if you want to validate as you type, you need a class of datagridtextboxcolumn and do the validation on its textbox keypress event.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|