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

Changing column SortingState --> no refresh (paint)

3 Answers 75 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Sebastian Talamoni
Top achievements
Rank 1
Sebastian Talamoni asked on 27 May 2009, 03:54 PM
Hi,
I am using custom sorting.
I've tried to follow some suggestions in other thread regarding the use of Loaded event to set the initial sorting state for my columns.

void GenWiseRadGrid_Loaded(object sender, RoutedEventArgs e)
        {
            if (ItemsControl != null)
            {
                Sorting += GenWiseRadGrid_Sorting;

                if (DataContext != null)
                    ApplySortToGrid(BaseProvider.DefaultSort);
            }
        }

        private void ApplySortToGrid(ISort pSort)
        {
            if (pSort == null) throw new ArgumentNullException("pSort");

            var name = BaseProvider.DefaultSort.DataProperty.PropertyName;
            var column = Columns[name];

            column.SortingState = BaseProvider.DefaultSort.Order.IsAscending ? SortingState.Ascending : SortingState.Descending;
            column.HeaderText = "test";

the ApplySortToGrid gets called, but the control does not repaint/refresh.

I've tried :
  InvalidateVisual();
            InvalidateArrange();
            UpdateLayout();

           
Nothing seems to get the control to repaint/ refresh...




We are not using SortDescriptions
if (SortDescriptions.Count > 0) throw new Exception("WE SHOULD NOT USE SORT DESCRIPTORS");

  <telerik:GridViewDataColumn HeaderText="Category Name" UniqueName="Category_name"
                                                    IsCustomSortingEnabled="True"
                                                    DataMemberBinding="{Binding Category.Category_name}"                                                >
                        </telerik:GridViewDataColumn>

Also I've noticed that the data is STILL sorted internally (so i return a list in a certain order but the grid will show it desc). I am doing the DESC already internally in my SQL engine .

Any idea???


3 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 28 May 2009, 12:10 PM
Hello Sebastian,

Can you please call Rebind() for the grid and let me know about the result?

Best wishes,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Sebastian Talamoni
Top achievements
Rank 1
answered on 03 Jun 2009, 09:31 AM
Vlad,

this.Rebind() will cause an stack overflow exception because radGrid_Loaded gets called again and again...

I've tried then with a small flag to avoid the stack overflow.

 

        void GenWiseRadGrid_Loaded(object sender, RoutedEventArgs e)

        {

            if (DataContext == null) return;

 

                if (BaseProvider.DefaultSort != null)

                    ApplyInitialSorting();

          

        }

 

        private bool _initialSorting;

 

        private void ApplyInitialSorting()

        {

            if (_initialSorting) return;

  
             ApplySortToGrid(BaseProvider.DefaultSort);

            _initialSorting = true;

            Rebind();

 

        }

And still did not worked, but the solution was also to add:

Columns.Reset() (no need for Rebind)

The Column reset seems to be the key problem for the Initial Sorting.


But still after this problem there is a second problem : The 2nd time the sorting seems to ignore the IsCustomSorting..

What's not clear to me is in what moment are the SortDescriptions modified?
The initial sorting does not raising:
 SortDescriptions.CollectionChanged += SortDescriptions_CollectionChanged;

but later clicking on the columns  (which raises the sorting) actually DOES modify the SortDescriptions collection...
In theory the SortDescriptions should NOT BE modified when using custom sorting...
I can send an image from the call stack where it shows that the
PersonSorting is called with parameter = addSortDescription = false

but then in the :
RadObservablecollection  ResumeNotifications() --> OnCollectionChanged() --> SortDescriptions_CollectoinChanged.

UPDATE: OK, got the solution to the 2nd problem.
In the _Sorting there is a e.Cancel (instead of the standard(?) e.Handled ) That was the trick. but I think this is one of the 1st times I got confused by Telerik API ....

e.Handled should not be the same as e.Cancel ?

Sebastian
0
Vlad
Telerik team
answered on 03 Jun 2009, 10:55 AM
Hi Sebastian,

Generally e.Handled is related to RoutedEvents. Please check this article for more info:
http://msdn.microsoft.com/en-us/library/system.windows.routedeventargs.aspx

Greetings,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
GridView
Asked by
Sebastian Talamoni
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Sebastian Talamoni
Top achievements
Rank 1
Share this question
or