Hi,
Users have reported unexpected behaivour when XamGrid is bound to a dynamically updating collection and sorting/grouping settings cause new items to appear above the currently displayed rows (for those appearing below, no issues reported). This behaivour makes user open context menu on the unexpected item and it is obviously not what the want.
I cannot provide sample code yet this behaivour can be easily reproduced using WPF Samples Browser - XamGrid - Editing & Selection - Active Item:
- open the sample
- click on BONAP cell
- sort by Company TWICE
- Active item window shows Laurence Lebihan, and Active Item is out of visible area.
My understanding is that ActiveItem should always be kept in the visible area.
I am using the lastest available patch for 2015.2.
I tried to use ScrollCellIntoView as a workaround but failed. Is there any way to achieve the expected behaivour?
Alex
PS. UPDATE. I've run Xceed's grid sample and they do have aforementioned functionality implemented the way users expect - even when sorting/grouping changes selected item is kept in the view. Of course, it jumps a little inside the grid's rectangle, but this is OK compared to XamGrid's scrolling out of view completely.
Hello Alexander,
The xamGrid control doesn’t provide this functionality by default but you can handle the ColumnSorted event, reset the XamGrid ActiveItem and then ScrollCellIntoView(xamGrid.ActiveCell) to achieve your requirement.
I have attached a sample application for your reference.
Sincerely,
hi Svetla,
Thanks for your response.
However, suggested approach doesn't work when data is added after sorting/grouping changed thus still making xamGrid's behaivour unsuitable for our users.
I managed to handle it partially (for cases when no grouping present) by this piece of code execute whenever underlying collection is changed:
-----
if (AssociatedObject.ActiveCell != null)
{
var item = AssociatedObject.ActiveCell.Row.Data;
var c2 = AssociatedObject.ActiveCell.Row.Cells[AssociatedObject.ActiveCell.Column.Key];
AssociatedObject.ActiveItem = null;
AssociatedObject.ActiveItem = item;
AssociatedObject.ScrollCellIntoView(c2);
AssociatedObject.ActiveCell = c2;
}
----
This allows me to keep active cell in view (it is being scrolled to the first/last visible row depending on sorting order and added item's property values).
When grouping is on, this code doesn't work - selected cell is reset upon underlying collection's change.
In both cases, collection fires Reset event to reflect its massive changes.
I'd appreciate any ideas which would allow to keep active cell in grouping mode as well.