Click here to Skip to main content
15,901,283 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my application i have two data grid. The 1st data grid consists of different Locations, so selection of one Item in the 1st datagrid will populate the respective locations Name and Age in the second datagrid

The binding is done like this
C#
ObservableCollection<Location> LocationObj
{
get;
set;
}


the above mentioned LocationObj is bound to the 1st datagrid and the selecteditem is bound to the SelectedLocation Property

C#
Location SelectedLocation
{
get;
set;
}



The class Location contains an ObservableCollection of name and age 3
In the second datagrid the ItemsSource is set to SelecetedLocation.Details which contains the ObservableCollection of age and Name.
When ever the user edits an Age, I would like the SelectedLocation to be sorted by Age.

How can i achieve this??
Posted
Updated 29-Feb-12 20:27pm
v2

1 solution

If you want to sort a column on the WPF Datagrid, you can try this link.

Sort WPF Datagrid column programmatically[^]

By the way, do not put your question text inside a code block. That is meant only for code alone. Thanks.
 
Share this answer
 
Comments
arun_pk 1-Mar-12 1:06am    
Sory the link you provided will is applicable only when u have one grid .. when ever selection of the second grid changes the collection view source is not helping much ..
Nithin Sundar 1-Mar-12 1:09am    
Well only your second grid's age column requires sorting I guess? You aren't sorting anything in the first because it contains locations right?
arun_pk 1-Mar-12 1:15am    
yeah..
when i select each item of the first grid the second grid values will change..
CollectionView source helps only to sort first time.. that is on load .. the first grid's first item is selected .. So now if i change the second grids age coloum the values are sorted but again if is select the first grids another location item .. the second grids sorting is not workin any more :(
Nithin Sundar 1-Mar-12 1:42am    
Well it looks to me that when the ItemsSource is changed, the sorting doesn't seem to exist. How about you add a umm PropertyChanged event handler for the second grid ItemsSource and repeat the sort process.
arun_pk 1-Mar-12 1:45am    
Sorry ididnt understand :(

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