This is a migrated thread and some comments may be shown as answers.

Sorting event not called if source is gridview itself

3 Answers 185 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Christian
Top achievements
Rank 1
Christian asked on 17 Mar 2011, 03:46 PM
Hello everyone,

we have the following use case: a RadGridView with a Details section where both, the row and the details section has editable contents. If someone changes a property (either in a cell or in a control inside the details section) we need to defer sorting actions of the rad grid view in order to prevent the current item to be sorted "out of scope". This happens if you have a lot of items, sort by property 1 ascending, then change the value of "A" to "Z" (which re-sorts the current item to the end of the list).

We tried hooking up to sorting event and set the cancel flag to "false" but it is not called if you the cell is commited on focus lost. We tried also to set ActionOnLostFocus to none, but after clicking on a empty region inside the details element (i.e. not a button) the current cell is committed and the gridview re-sorts itself.

Any advise how to prevent the grid to automatically sort our current selected item out of view?

Example:

<telerik:RadGridView Sorting="Grid_Sorting"  x:Name="Grid" ActionOnLostFocus="None" AutoGenerateColumns="False" RowDetailsVisibilityMode="VisibleWhenSelected">
         <telerik:RadGridView.Columns>
             <telerik:GridViewDataColumn IsReadOnly="False" DataMemberBinding="{Binding FormOfAddress}">
                 <telerik:GridViewDataColumn.CellEditTemplate>
                     <DataTemplate>
                         <ComboBox SelectedItem="{Binding FormOfAddress}" ItemsSource="{Binding AvailableFormOfAddresses}" />
                     </DataTemplate>
                 </telerik:GridViewDataColumn.CellEditTemplate>
             </telerik:GridViewDataColumn>
         </telerik:RadGridView.Columns>
         <telerik:RadGridView.RowDetailsTemplate>
             <DataTemplate>
                 <Border Background="Red" Width="100" Height="100">
                     <StackPanel>
                         <!-- Clicking on this text commits the ComboBox and re-sorts the grid -->
                         <TextBlock Text="{Binding FormOfAddress}" />
                           
                         <!-- Clicking on this button does not commit the ComboBox -->
                         <Button Content="Save" />
                     </StackPanel>
                 </Border>
             </DataTemplate>
         </telerik:RadGridView.RowDetailsTemplate>
     </telerik:RadGridView>

Code behind:
private void Grid_Sorting(object sender, Telerik.Windows.Controls.GridViewSortingEventArgs e) {
    Debug.WriteLine("Sorting called.");
}

The output "Sorting called" is only shown if a user sorts the column, but if the grid itself re-sorts it this text is not printed and therefore can't be canceled.

Version: RadControls for WPF Q1 2011

Thanks in advance,

Christian

3 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 17 Mar 2011, 03:49 PM
Hi,

 Indeed this is expected behavior. Sorting event will be raised only when you sort by columns using the grid UI.

Regards,
Vlad
the Telerik team
0
Christian
Top achievements
Rank 1
answered on 17 Mar 2011, 04:00 PM
Ok, thanks.

Is there any way to prevent the grid to auto re-sort itself in order to fix the "item disappears issue"? Or how can i prevent the cell from committing itself if it looses its focus (i thought that's what ActionOnLostFocus is for but it's already set to "None").

Any advice would be great!
0
Vlad
Telerik team
answered on 21 Mar 2011, 08:23 AM
Hello,

 As far as I can see you have custom CellEditTemplate - you can embed your custom logic here. You will need to play with SelectedItem binding for the combo. 

All the best,
Vlad
the Telerik team
Tags
GridView
Asked by
Christian
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Christian
Top achievements
Rank 1
Share this question
or