Anyway to force row/cell validation

10 posts, 0 answers
  1. Lasse
    Lasse avatar
    21 posts
    Member since:
    Jul 2011

    Posted 23 Jan 2012 Link to this post

    Hi,

    Is there anyway to force row/cell validation from outside the grid?
    Is there anyway to force data back to the data-set before validation?

    Regards
    Svein Thomas
  2. Jack
    Admin
    Jack avatar
    2333 posts

    Posted 26 Jan 2012 Link to this post

    Hi Svein Thomas,

    Thank you for contacting us. Directly to your questions:

    1. CellValidating and RowValidating events fire when the current cell/row is being changed or when ending an edit operation. You can force these events to fire by setting the CurrentRow/CurrentColumn properties to different value or by calling the EndEdit method to finish the current edit operation.

    2. No values are changed in the data source before validation. However, I am not sure that I fully understand your scenario. Please, could you elaborate a bit more and describe in detail what you want to achieve. I will be glad to assist further.

    I am looking forward to your reply.
     
    Regards,
    Jack
    the Telerik team

    SP1 of Q3’11 of RadControls for WinForms is available for download (see what's new).

  3. Bob
    Bob avatar
    41 posts
    Member since:
    Mar 2012

    Posted 20 Jun 2012 Link to this post

    I think I am looking for the same effect.

    I have a grid with values in it; quantity, price, discount (%), unit price.

    If the user wished to place a discount on each row, they enter it once, and then in a For Each loop, I place the value in the cell; however the calculation does not take place.  it appears as if the CellValidating or RowValidating events are not firing. 

    Here is my snipit of code:

    For Each r As GridViewDataRowInfo In InvoiceDetailsGridView.Rows
        r.Cells("colDiscount").Value = DiscountTextBox.Value
    Next
    InvoiceDetailsGridView.Refresh()

    The user can manually enter a value in the discount field, and the calculation takes place.

    Any ideas?

    Thanks
    Bob
  4. Bob
    Bob avatar
    41 posts
    Member since:
    Mar 2012

    Posted 20 Jun 2012 Link to this post

    I placed a BeginEdit / EndEdit around the cell update.
    However in my for each loop, the last row is not being updated...I'll look a little deeper.
    Thanks
  5. Bob
    Bob avatar
    41 posts
    Member since:
    Mar 2012

    Posted 20 Jun 2012 Link to this post

    OK - sorry for the drawn out process.

    When I go through the loop, the last row is not displaying the calculated value, although the CellEndEdit event is fired performing the calculation and placing the values in the right cell.  When I run through the loop once more, the same thing happens; the last row does not update with the current value, but displays the results of what should have been there from the previous calculation.

    Hope that makes sense. 

    Any ideas?

    Thanks
  6. Jack
    Admin
    Jack avatar
    2333 posts

    Posted 25 Jun 2012 Link to this post

    Hello Bob,

    Could you please send us your application and describe in detail the exact behavior that you want to achieve? This will help us to understand the exact scenario and to provide you with a working solution. Please note that CellValidating event fires only when changing the cell value using the user interface. This method will not fire when setting the cell value with code.

    I am looking forward to your reply.
     
    Greetings,
    Jack
    the Telerik team
    RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
  7. Bob
    Bob avatar
    41 posts
    Member since:
    Mar 2012

    Posted 25 Jun 2012 Link to this post

    Thank you for the reply.

    Ok, to make sure I understand, when I update a field through code, the calculations will not take place due to the CellValidating event not firing.  If that is the case, is there a way to fire that event or do I have to manually calculate the values and manually update each field?

    I need to break out the portion of code and will get that shortly; just wanted to follow up with the question above.

    Thanks
    Bob
  8. Jack
    Admin
    Jack avatar
    2333 posts

    Posted 28 Jun 2012 Link to this post

    Hi Bob,

    Yes, your assumption is correct. In this case the CellValidating event will not fire. I am not sure whether it helps, however you can force this event to fire by using the EventDispatcher class. Here is a sample:
    GridViewRowInfo row = this.radGridView1.Rows[1];
    GridViewColumn column = this.radGridView1.Columns["Value"];
    object oldValue = row.Cells["Value"].Value;
    object newValue = 10;
    CellValidatingEventArgs cellValidating = new CellValidatingEventArgs(row, column, newValue, oldValue, null);
     
    this.radGridView1.MasterTemplate.EventDispatcher.RaiseEvent<CellValidatingEventArgs>(EventDispatcher.CellValidating,
        this.radGridView1, cellValidating);
    if (!cellValidating.Cancel)
    {
        row.Cells["Value"].Value = newValue;
    }

    If you need further assistance, I will be glad to help.
     
    All the best,
    Jack
    the Telerik team
    RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
  9. Bob
    Bob avatar
    41 posts
    Member since:
    Mar 2012

    Posted 28 Jun 2012 Link to this post

    Hi Jack,

    Thanks for the information.

    I ended up using the CurrentRow.InvalidateRow() method in the CellEndEdit event of the the grid to perform the calculations.
    Interesting that it works, just not sure I understand how.

    Thanks for the help; you guys are great!
    Bob
  10. Jack
    Admin
    Jack avatar
    2333 posts

    Posted 03 Jul 2012 Link to this post

    Hello Bob,

    I am glad to hear that you have found a solution for this issue.

    The InvalidateRow method synchronizes the visual row element with the row content in the data layer. So, this seems to be a potential issue. Please, could you send me your application and describe the exact steps to reproduce it. We will investigate it and if there is an issue, we will try to address it in our upcoming service pack.

    Thank you in advance.

    I am looking forward to your reply.
     
    Greetings,
    Jack
    the Telerik team
    RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
Back to Top