in RowValidating, e.Row.IsModified doesnt show as true, when it should

4 posts, 0 answers
  1. ShareDocs
    ShareDocs avatar
    91 posts
    Member since:
    Oct 2012

    Posted 24 Sep 2013 Link to this post



    Hi, I have a GridView.

    when I make a change in a cell of one row, and then I select to add a new row the event grid_RowValidating  its fier but when I do e.Row.IsModified I always get FALSE.

    Only if I press in other row before I press to add a new row to the grid.

    private void grid_RowValidating(object sender, RowValidatingEventArgs e)
           {
                   if (e.Row == null) return;
                   if (!e.Row.IsModified) return; 
            
           }



     the way to reproduce this is.

    - Edit a cell from the gridView.
    - Click to add new Row

    e.Row.Index indicate that its checking the row I just edited where i change some value, so it should show me that there is a change.
    I also tried adding the event RowChanged  but didnt work
    private void grdPirteyMenahel_RowsChanged(object sender, GridViewCollectionChangedEventArgs e)
          {
              grid.EndEdit();
          }


  2. Dimitar
    Admin
    Dimitar avatar
    2913 posts

    Posted 27 Sep 2013 Link to this post

    Hi Lior,

    Thank you for writing.

    This property works correctly for its purpose. Here is its description "Gets a value indicating whether the row has been modified and changes are not saved in the data layer." As long as a row value changes it is being saved in the data layer so this property will be false in most cases when accessed. However, it serves our internal logic, and this is why it exists.

    If you need to identify if a row value is changed the CellValueChanged event is suitable for that. The Tag property of the row can be set in the event mentioned and it can be checked when you need to know if the row is modified.

    Please let me know if there is something else I can help you with.

    Regards,
    Dimitar
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. ShareDocs
    ShareDocs avatar
    91 posts
    Member since:
    Oct 2012

    Posted 29 Sep 2013 Link to this post



    I need to identify if a row change and see their changes to validate the row
    i cannot validate the entire row when only one cell had change.
    i need to do this validation when rowValidating or RowChange or something like that, no in Cell Events.

    If I make a change in one row, and then i click in other row it works fine.
    it gives me the changes I had done and with that I can validate and if its not correct I can undo the changes.

    The problem only appear when after making a change in a row, I click to add a new row 
    then I dont get changes when calling to (grid.DataSource as DataTable).GetChanges()

  4. Dimitar
    Admin
    Dimitar avatar
    2913 posts

    Posted 02 Oct 2013 Link to this post

    Hi Lior,

    Thank you for writing back.

    The described approach does not suggest to validate anything in the CellValueChanged event. In this event you just have to set the row Tag property to a value that we can later use to determine whether or not the row is changed:
    void radGridView1_CellValueChanged(object sender, Telerik.WinControls.UI.GridViewCellEventArgs e)
    {
        e.Row.Tag = true;
    }
     
    Then can validate the data in the RowValidating by checking the Tag property:
    void radGridView1_RowValidating(object sender, Telerik.WinControls.UI.RowValidatingEventArgs e)
    {
        if (e.Row.Tag != null && (bool)e.Row.Tag == true)
        {
             //Validate data here
        }
    }

    Please let me know if there is something else I can help you with. 

    Regards,
    Telerik

    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS. 
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>

Back to Top