Phantom Row added between UserAddingRow and UserAddedRow events

4 posts, 0 answers
  1. Teddy
    Teddy avatar
    3 posts
    Member since:
    Sep 2011

    Posted 07 Jun 2018 Link to this post

    When we add a new row using the "grid1.UserAddedRow" event,  we update
    the value one of the columns "Weighting" for each row with the even
    spread of how many rows there are over 100 percent.
    So if there are 3
    rows initially, the "Weighting" field for each of the rows will be
    "33.33%". As soon as we add a new row, which makes the total number of
    rows 4,
    we update the value of the "Weighting" field for each of the rows to "25.00%".

    The issue occurs when we add our first row, instead of setting the "Weighting" to "100.00%", it sets it to "50.00%".
    Logically this means that there must be another row that exists in the grid whilst the user added row event is firing.
    When
    the "grid1.UserAddingRow" event fires, there is one row but when the
    "grid1.UserAddedRow" fires straight afterwards, the row count changes to
    2.
    Does the grid have another event that is adding a new row
    whenever you add your first record to the grid? How can we prevent this
    from happening?
  2. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    4170 posts

    Posted 07 Jun 2018 Link to this post

    Hello, Teddy,  

    RadGridView exposes several end-user events two of which you will find useful in the context of the new row: UserAddingRow and UserAddedRow. These events are fired when the user commits the new row (by pressing the Enter key or by clicking somewhere in the grid). As the name of the UserAddingRow implies, it allows for preventing the new row from being committed as a data row. This may be useful in case some of the data entered by the end-user is invalid according to some custom requirements. The UserAddedRow event is fired when the row is already added. In the GridViewRowEventArgs.Rows collection it is indicated how many rows are added in the current operation. Usually you are supposed to have 1 row only. If you want to detect how many rows there are in the grid, you can check the RadGridView.Rows collection. It always returns the correct rows number on my end. I have attached my sample project for your reference. 

    According to the provided information, I would suggest you consider using either summary rows or calculated columns. Thus, it wouldn't be necessary to execute any calculations programatically. Additional information is available in the following help article:
    https://docs.telerik.com/devtools/winforms/gridview/rows/summary-rows
    https://docs.telerik.com/devtools/winforms/gridview/columns/calculated-columns-(column-expressions)

    I hope this information helps. If you have any additional questions, please let me know. 

    Regards,
    Dess
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. Teddy
    Teddy avatar
    3 posts
    Member since:
    Sep 2011

    Posted 07 Jun 2018 in reply to Dess | Tech Support Engineer, Sr. Link to this post

    Hi Dess,

    Thank you for the response. I will attempt to use the calculated column but I also wish to allow the user to add their own custom values that will still add up to 100%

    For example:

    Row 1 "Weighting" = 20.00%

    Row 2 "Weighting" = 50.00%

    Row 3 "Weighting" = 30.00%

    will this be possible using the calculated column?

  4. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    4170 posts

    Posted 11 Jun 2018 Link to this post

    Hello, Teddy,  

    I would like to clarify a little bit the difference between summary rows and calculated columns. Summary rows accumulate the values from the same column and different rows, e.g. row1=10, row2=20, row3=30 => summary row's value=60. The user can enter any value and the summary row will automatically sum the values. However, the calculated columns evaluate the applied expression considering the specified cell's values on the same row. I think that summary rows are more appropriate for your case. It would be useful if you have a look at the referred help articles from my previous reply for further information.

    I hope this information helps. If you have any additional questions, please let me know. 

    Regards,
    Dess
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top