Sorting with custom GridViewRow Template

2 posts, 0 answers
  1. GPJ
    GPJ avatar
    31 posts
    Member since:
    Oct 2008

    Posted 07 Jul 2009 Link to this post

    I have a "hidden" column (made visible for debugging) called "Index" that I am sorting by...  When I first load the grid, the grid is loaded in the correct way - but probably because my list of objects is already sorted.  I implemented some custom commands attached to buttons inside the GridViewRow Template for moving objects UP or DOWN in the grid.  When the Move Up or Move Down buttons are pressed, the items are removed from the list, inserted at the right location and the list's Index properties are corrected for the new order...

    BUT The first time I press Move Up or Move Down, the index changes (I see the indexes in the data records change), but the grid doesn't refresh the items.   The NEXT time I press either button, the grid resorts but not in a nice way...  Items are always in the wrong order.

    For example:

    Start with these objects in the grid
    1 - AAA
    2 - BBB
    3 - CCC

    Move Down for object AAA: Remove object AAA, insert at new spot in list, reindex.  Grid shows:
    2- AAA
    1 - BBB
    3 - CCC

    Move Down for object AAA: Remove object AAA, insert at new spot in list, reindex.  Grid shows:
    2 - CCC
    1 - AAA
    3 - BBB

    I may have to put a small sample together but I'm hoping not. Here is how I  have my grid defined:

                <telerik:RadGridView x:Name="SettingsGrid" ItemsSource="{Binding ElementName=UC, Path=CurrentTeamProjectList}" ScrollMode="RealTime"  
                                         AutoGenerateColumns="False" ShowGroupPanel="False" IsFilteringAllowed="False" ColumnsWidthMode="Fill" ShowColumnHeaders="False" 
                                         CanUserFreezeColumns="False" CanUserReorderColumns="False" CanUserSortColumns="False" VerticalGridlinesVisibility="Hidden" 
                                         Margin="4,2,4,2" Loaded="SettingsGrid_Loaded"
     
                    <telerik:RadGridView.Columns> 
                        <telerik:GridViewDataColumn UniqueName="Index" IsReadOnly="True" DataType="{x:Type System:Int32}"/> 
                        <telerik:GridViewDataColumn UniqueName="Name" IsReadOnly="True" DataType="{x:Type System:String}"/> 
                        <telerik:GridViewDataColumn UniqueName="Boolean1" DataType="{x:Type System:Boolean}"/> 
                        <telerik:GridViewDataColumn UniqueName="Boolean2" DataType="{x:Type System:Boolean}"/> 
                        <telerik:GridViewDataColumn UniqueName="NumSeconds" DataType="{x:Type System:Int32}"/> 
                    </telerik:RadGridView.Columns> 
                    <telerik:RadGridView.SortDescriptions> 
                        <cm:SortDescription PropertyName="Index" Direction="Ascending" /> 
                    </telerik:RadGridView.SortDescriptions> 
                </telerik:RadGridView> 
     

    I tried adding a SortDescription object to the SortDescriptions collection in the grid loaded event, but that did the same thing.

    Thoughts?
    Greg
  2. GPJ
    GPJ avatar
    31 posts
    Member since:
    Oct 2008

    Posted 08 Jul 2009 Link to this post

    I have figured out (sort of) what was going on. 

    My Objects were in a BindableList<> .. which I expected that "removing and re-inserting" the objects would raise the list changed event and force the grid to refresh... Well, that didn't work.

    I implemented the INotifyPropertyChanged interface on my objects and now it seems to be working as expected.  (I left the remove/insert code in because I want my list to be in the order of the indexes).

    It doesn't explain why after moving up/down twice the grid started to resort itself (albeit incorrectly), but it's working, so I'm happy!

    Greg
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top