This is a migrated thread and some comments may be shown as answers.

Phantom Row added between UserAddingRow and UserAddedRow events

3 Answers 12 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Teddy
Top achievements
Rank 2
Teddy asked on 07 Jun 2018, 12:45 PM
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?

3 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 07 Jun 2018, 01:32 PM
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.
0
Teddy
Top achievements
Rank 2
answered on 07 Jun 2018, 02:15 PM

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?

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 11 Jun 2018, 05:45 AM
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.
Tags
GridView
Asked by
Teddy
Top achievements
Rank 2
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Teddy
Top achievements
Rank 2
Share this question
or