Results 1 to 6 of 6

Thread: Datagrid / DataTable Query

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2003
    Posts
    153

    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

  2. #2
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    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

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2003
    Posts
    153
    Heres a chunk of the code.


    VB Code:
    1. Character = CurrentRow.Item(Column)
    2.  
    3. If Not(Character = "P" Or Character = "R" Or Character = "F" Or Character = " ") Then
    4.  
    5. Throw New Exception("Invalid Cell Input, Please Insert P, F, or R.")
    6.  
    7. 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.

  4. #4
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    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

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Aug 2003
    Posts
    153
    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?

  6. #6
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    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
  •  



Click Here to Expand Forum to Full Width