Last Updated: 28 Oct 2021 14:07 by Jakob
Created on: 19 Oct 2021 09:52
Category: GridView
Type: Bug Report
RadGridView: SelectedRows returns 0 for preselected rows when using Begin/EndUpdate

There are situations where SelectedRows won't return the number of rows preselected when using Begin/EndUpdate even though it seems like there's a row selected in the UI. By preselected I mean the row that looks selected after the rows has been added. This bug has caused some problems for us because the user tried some action on a row they thought was preselected and it would fail.

One situation I found where this bug can be reproducted is by using SortOrder in combination of Begin/EndUpdate. There are probably more situations but I hope this one will let you find the underlying bug.

The attached project contains a simple form with a RadGridView which will contain a list of persons. The list is populated by this method:

public void PopulateGridView(List<Person> persons)
	PersonGridView.DataSource = persons;
	PersonGridView.Columns[nameof(Person.LastName)].SortOrder = RadSortOrder.Ascending;

There are two buttons: "Step one" and "Step two". The first will mimick a situation where the user search a database for persons and none will be found. By clicking the "Get selected rows" you will see that the SelectedRows will return zero rows which is correct.
But when you afterwards click "Step two" (which will add five rows) it seems like there's one row preselected. I would expect the SelectedRows to return that row but by clicking "Get selected rows" again you will see that the returned rows are zero still. The CurrentRow, however is set to the preselected row as expected.
If you start by clicking "Step two" the SelectedRows actually returns the correct rows. Quite strange :-)

I know this is a very small issue and can be avoided. But as I mentioned there are other situations where this problem occurs and it's quite hard to figure out exactly what causes it.

Thank you for your help.

Best regards
Ulrik Skovenborg

Attached Files:
Posted on: 28 Oct 2021 14:07

Thank you for your answer. That's a fine workaround and as you say the recommended way.

I guess I didn't quite understood when Begin/EndUpdate was appropriate to use. I thought it was useful when you set the DataSource because you kind of update all cells... or so I thought :-)

Thanks for clarifying the idea behind Begin/EndUpdate.


Dess | Tech Support Engineer, Principal
Posted on: 25 Oct 2021 12:21

Hello, Jakob,

The provided sample project is greatly appreciated. I would like to note that when RadGridView is populated with data and you update a certain cell/row, the grid will update its layout. The more edit operations occur, the more visual updates will be performed. This will inevitably affect performance. In such cases, it is good to use Begin/EndUpdate in order to reduce the visual refreshing of RadGridView to one time. However, it is not recommended to use it when setting the DataSource for example because in the Begin/EndUpdate block, the notifications in RadGridView will be suspended.

A certain data row can be selected or current, or selected and current at  the same time. The highlighted row is actually the CurrentRow in the grid. In the Fluent theme, the current row has a blue fill color as well. Since the behavior is not identical when clicking the second button first, I have approved this item for further investigation.

I have also updated your Telerik points

Meanwhile, feel free to remove the BeginUpdate/EndUpdate block when setting the DataSource.

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Dess | Tech Support Engineer, Principal
Progress Telerik

Remote troubleshooting is now easier with Telerik Fiddler Jam. Get the full context to end-users' issues in just three steps! Start your trial here - https://www.telerik.com/fiddler-jam.