Issue with RowCount in RowChanging event.

Hi again.


Having any grid with sorting enabled (SortSettings.Show := true) and the ability to keep focused row selected (Navigation.MoveRowOnSort := true) will report wrong RowCount in RowChanging event, when using QSort.

This is caused by the fact that 3 ekstra rows are added to the grid. (havent researched why - don't care). 
But in advgrid.pas line 43003 and 43004

        if (cr <> Row) and Assigned(FOnRowChanging) then
          FOnRowChanging(Self,cr,Row,Allow);

RowChanging is triggered before RowCount is properly reset to (RowCount-3).

This is causing some problems in trying to catch the situation of having focus on last row - after sorting is done.

Can I work around this - or can this be fixed in a new release?

Kind Regards
Bjarne Rasmussen

It is for performance reasons that temporarily extra rows are allocated.We can't change this. Not sure for what reason you need RowCount but if there is a must to have this from the OnRowChanging event, take these extra rows in account while sorting.

Hi Bruno.


I need to make it clear for users - whenever they visibly are positioned on the last row in the grid.
To do this - I implement OnRowChanging event.

Sorting is enabled - and so is MoveRowOnSort.

Whenever a user shifts sort from ascending (while having focus on first row) to descending. Row focus will obviously go from first to last row. But trying to show any data from the last row in the OnRowChanging event gives me nothing (newrow value is incorrect - 3 higher than it should be).

So any attempt to show data from advstringgrid1.Cells[1,newrow] will result in empty or wrong data.

Moving around with arrow keys is OK. And going from first to last row with home/end keys also works ok.

I only need to be able to show data from the current selected row - when sorting. And this only fails if first row is focused and you reverse the sort and end up having focus on the last row.

I can of course make a demo program to show you. But I think this explains it perfectly.

Let me know.

Kind Regards.
Bjarne Rasmussen

I would suggest to disable the code in OnRowChanging during the sort. Before the sort starts, grid.OnCanSort() is triggered where you can disable OnRowChanging and after the sort, grid.OnClickSort() is triggered from where you can enable OnRowChanging again.

Thank you for this workaround.

Perhaps the issue could be added to OnRowChanging documentation? :-)

/Bjarne