Is there a way to sort a WPF DataGrid programmaticaly ( for example, like if i clicked on my first column).
Is there a way to simuate this click ? Or a best way ?
you can use ICollectionView to filter, sort and group your items in a datagrid.
EDIT: add Sort, did not read the question carefully :)
var view = CollectionViewSource.GetDefaultView(this.MyData);
view.Filter = ViewFilter;
view.SortDescriptions.Add(new SortDescription("MyPropertyToSort", ListSortDirection.Descending));
private bool ViewFilter(object obj)
{
var item = obj as MyObject;
if (item == null)
return false;
//your filter logik goes here
if(item.MyStringProp.StartsWith("Test"))
return false;
return true;
}