Hi,I have a XamGrid binding to a collection of objects.A column of the grid is sorted (IsSorted="Ascending") and when data are loaded the sort condition is applied correctly so rows are displayed in the correct sort order but when data changed sorting is not applied.Is there a way to get sorting automatically applied when data changed?
Hello vsolutions,
I reviewed your requirements and I can suggest you programmatically sort the fields when a value is changed(for example by handling the CellExitedEditMode event of the XamGrid ) or when the record is added. For example if you have a column named “number” and you want the XamGrid to be sorted by it, you can try something like:
private void XamGrid_CellExitedEditMode(object sender, Infragistics.Controls.Grids.CellExitedEditingEventArgs e)
{
if ((sender as XamGrid).ActiveCell.Column == grid1.Columns["number"])
grid1.ColumnLayouts[0].SortingSettings.SortedColumns.Add(grid1.Columns["number"] as TextColumn);
}
For further reference you can look at our documentation:
http://help.infragistics.com/NetAdvantage/Silverlight/2011/1/CLR4.0/?page=SL_xamGrid_Editing_Data.html .
If you need any further assistance on the matter I will be glad to help.
Hi Elena,thank you for your reply.
Your solution could be good in case data are update by the user editing the grid cells.
In my case data are update by code so CellExitedEditMode event is not fired and I haven't any event that notify when data are changed.The problem is that when the data in the object model are changed the grid correctly displays the new values (so the grid is notified about data updates) but sorting is not applied to the new values.At the same time filtering conditions are applied to the grid and this works correctly, so I figure out that sorting has to work like filtering but it is not.
Is there a solution?
In case you don’t know when the data is added you may try handle the initializing of the new row in the XamGrid. I can suggest you try:
private void grid1_InitializeRow(object sender, InitializeRowEventArgs e)
grid1.ColumnLayouts[0].SortingSettings.SortedColumns.Clear();
Is this still doesn’t suit your scenario please do not hesitate to ask.
I am still looking into your requirements and since the above solution may cause some performance issues I can also suggest you handle the OnColletionChanged and INotifyPropertyChanged events of the collection you use for the source and resort the XamDataGrid form there.
Hi Elena,I've solved my problem using a custom collection, the problem occurred with observable collection.I think your last suggestion could be equally good.Thank you very much.Andrea Tasca