Click here to Skip to main content
15,884,986 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a DataGrid and bound an ObservableCollection to it:

C#
ObservableCollection<Values> MyValueList = 
            new ObservableCollection<Values>();

public MainWindow()
{
   gridViewReceivedValues.ItemsSource = MyValueList;
}


If I do
C#
MyValueList.Add(SomeValue);

the value is added to my collection and because of the binding also shown in the DataGrid.

BUT it adds all my values BELOW all the others, but the newest value should be first.

No problem I thought. My value objects contain a DateTime field on witch i could sort the DataGrid.

But that was not as easy as I thought. After 2 hours of trial and error I still cannot sort the DataGrid.

So my Question is: How do I sort a DataGrid initialy in code?!

Best regards
Chris
Posted

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900