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

SelectedItem is null after cell edit and auto sort

1 Answer 50 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 12 Jun 2012, 01:25 PM

 Hi, 
    I have a RadGridView bind to a datatable and sort by Name column. My problem is after I modify the Name column, the RadGridView performs a 'auto sort' and the current selected row is deselected and the SelectedItem is Nothing.

    How can I preserve the selected row after the 'auto sort'?

Thanks,
Chris



<
telerik:RadGridView  DockPanel.Dock="Top" x:Name="gv"  SelectionMode="Single" RowHeight="30"
                                                IsSynchronizedWithCurrentItem="True" AutoGenerateColumns="False" ShowGroupPanel="False" >
                              <telerik:RadGridView.Columns>
                                  <telerik:GridViewDataColumn DataMemberBinding="{Binding Path=Name}" Header="Name" UniqueName="Name" />
                                  <telerik:GridViewDataColumn DataMemberBinding="{Binding Path=PhoneNumber}"  Header="Phone Number" />
                                  <telerik:GridViewDataColumn DataMemberBinding="{Binding Path=City}" Header="City"  />
                                  <telerik:GridViewDataColumn DataMemberBinding="{Binding Path=State}" Header="State"  />                                </telerik:RadGridView.Columns>
                                  <telerik:RadGridView.SortDescriptors>
                                      <telerik:ColumnSortDescriptor  Column="{Binding Columns[\Name\], ElementName=gv}"
                                             SortDirection="Ascending" />
                                  </telerik:RadGridView.SortDescriptors>
 
                              </telerik:RadGridView>

1 Answer, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 13 Jun 2012, 03:33 PM
Hi Chris,

The reason why this behaviour occurs is that when the value by which the item is sorted is changed the GridView executes a kind of rebind logic, where the SelectedItem is reset.  

 You could set the IsSyncronizedWithCurrentItem property of the GridView to True and that way the SelectedItem will be always the CurrentItem.
 

Regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
GridView
Asked by
Chris
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Share this question
or