Home Forums WinForms controls Xceed Grid for WinForms Grid Validation

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #12706 |

    I have an unbound grid. When I enter a new datarow and then click on a save button at the top of my form, I need to validate the current row of the grid and then prevent the focus from leaving the current row and changing to the save button if the row doesn’t validate. Anyone have any suggestions.
    Thanks, Jeff

    Imported from legacy forums. Posted by Jeff W (had 4865 views)

    Xceed Support
    Member
    Post count: 5658

    Hi Jeff,

    Custom validation can be provided at either the row or the cell level depending on the kind of validation you want to provide. For example, for values entered into an InsertionRow, custom validation would be provided at the row level since “normally”, the user would be allowed to enter all the values in a row before they are validated. In other cases, such as when modifying existing values in the grid, validation would be done at the cell level because “normally” you would allow the user to change the value of only one cell.

    Custom row validation is done using the EndingEdit and ValidationError events. In the EndingEdit event, the custom validation is provided and in the ValidationError event, you can decided if you want to allow the row to exit edit mode in the case where the values of one or more of its cells do not pass the validation process.

    The row’s ValidationError event will be raised if e.Cancel is set to true in the EndingEdit event and/or if an exception is thrown in the EndingEdit event.

    Custom cell validation is done using the LeavingEdit and ValidationError events. In the LeavingEdit event, the custom validation is provided and in the ValidationError event, you can decided if you want to allow the cell to exit edit mode in the case where its value does not pass the validation process.

    The cell’s ValidationError event will be raised when e.Cancel is set to true in the LeavingEdit event, when an exception is thrown in the LeavingEdit event and/or when a validation exception is thrown by the underlying datasource.

    If you need some code, let me know 🙂

    BTW, I have completely revamped the topic on validating in the help file (for version 2.0 of the grid) which will make it alot clearer than it is now 🙂

    I hope this helps!

    Imported from legacy forums. Posted by Jenny [Xceed] (had 1038 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks for the help Jenny. I have subscribed to the datarow templates EndingEdit and ValidationError events. The Ending Edit event fires just fine when I edit a row and then move to another row. However, if I edit a row and then click on a save button at the top of my form, the Ending Edit event doesn’t fire. I also have the buttons Causes Validation property set to True.
    Thanks, Jeff

    Imported from legacy forums. Posted by Jeff W (had 593 views)

    Xceed Support
    Member
    Post count: 5658

    Calling EndEdit on the CurrentRow should do the trick. For example, in your Save button:

    if( ( ( DataRow )gridControl1.CurrentRow ).IsBeingEdited )
    ( ( DataRow )gridControl1.CurrentRow ).EndEdit();

    Of course, you will need to check the type of the current row before casting to avoid exceptions. 😉

    Imported from legacy forums. Posted by Jenny [Xceed] (had 463 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks so much for your help Jenny. That worked. 🙂

    Imported from legacy forums. Posted by Jeff W (had 418 views)

    Xceed Support
    Member
    Post count: 5658

    Glad I could help 🙂

    Imported from legacy forums. Posted by Jenny [Xceed] (had 422 views)

    User (Old forums)
    Member
    Post count: 23064

    Jenny,

    regarding the validation error. I did not use the e.cancel or leavingedit etc… i just call a method when the user presses a button.. HOwever, when the user enters the correct data for the second time, the error icon or message does not disappear.. Why? This is the method i will call:

    private int CheckRequired(ArrayList ar, Xceed.Grid.DataRow dr)
    {
    int noDTErrors=0;
    for(int i=0;i<ar.Count;i++)
    {
    try
    {
    if(ar[i].ToString().Trim().Equals(“”))
    {
    this.validator.SetValidationError(dr.Cells[“Scanned”],”Required Field”);
    ++noDTErrors;
    }

    }
    catch(Exception x)
    {
    this.validator.SetValidationError(dr.Cells[“Scanned”],”Required Field”);
    ++noDTErrors;
    }

    }
    return noDTErrors;
    }

    Imported from legacy forums. Posted by peyton (had 6425 views)

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.