Pergunta

I have datagrid which is having 1 of the column as DataGridComboBoxColumn. Displaying of existing data, binding of itemsource, updating source when selection changes is working fine.

The problem is when i click on the header of the DataGridComboBoxColumn it is not sorting alphabetically. When I checked it is actually sorting as per value whereas i want it to sort as per display. When I searched on the net it was saying that I should use "SortMemberPath" property and assign this property to the property on which sorting should happen.

On doing this the sorting is working only for the first time the header is clicked but on subsequent clicks, there is no sorting taking place. I searched on the net but was not able to find a solution.

The following is my xaml for DataGridComboBoxColumn

<DataGridComboBoxColumn Header="Database Name" 
                        SelectedValueBinding="{Binding Path=Databases.DatabaseID, Mode=TwoWay, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}"
                        ItemsSource="{Binding Source={StaticResource ManageTablesVMInstance}, Path=Database}"  
                        SelectedValuePath="DatabaseID" DisplayMemberPath="DatabaseName" SortMemberPath="DatabaseName" />

Type of some of the terms used above

Databases - ObservableCollection

ManageTablesVMInstance - instance of ViewModel

Database - ObservableCollection

Please let me know if any other information is required from my side. I am using .net 4.0.

Please help.

Thanks in advance.

Regards,

Samar

Foi útil?

Solução

I found out the solution by myself. In the SortMemberPath instead of just "DatabaseName" i should put "Databases.DatabaseName". The sorting works as expected after doing this. So the xaml will look like this.

                    <DataGridComboBoxColumn Header="Database Name" 
                        SelectedValueBinding="{Binding Path=Databases.DatabaseID, Mode=TwoWay, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}"
                        ItemsSource="{Binding Source={StaticResource ManageTablesVMInstance}, Path=Database}"  
                        SelectedValuePath="DatabaseID" DisplayMemberPath="DatabaseName" SortMemberPath="Databases.DatabaseName" />

Surprisingly nobody answered this question. I wonder why.

Regards,

Samar

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top