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

[Solved] ReorderColumns not working as expected with Q3 09 Release

8 Answers 124 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Randall Nelson
Top achievements
Rank 1
Randall Nelson asked on 09 Nov 2009, 07:55 PM
After upgrading from the Q2 to Q3 releases, the ReorderColumns function doesn't seem to work as it used to. 

In the sample code below, I have a class that the grid is bound to.  The grid has four columns.  I'm hiding the first two columns and trying to reorder the columns so that the 4th column displays first and the 3rd column displays second.

I have validated that this code works correctly with the Q2 release.

<UserControl xmlns:telerikGridView="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"  x:Class="GridReorderIssue.MainPage" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"   
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"   
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">  
  <Grid x:Name="LayoutRoot">  
    <telerikGridView:RadGridView x:Name="gdMain" AutoGenerateColumns="False">  
            <telerikGridView:RadGridView.Columns> 
                <telerikGridView:GridViewDataColumn Header="One" UniqueName="One" IsVisible="False" /> 
                <telerikGridView:GridViewDataColumn Header="Two" UniqueName="Two" IsVisible="False" /> 
                <telerikGridView:GridViewDataColumn Header="Should be 2nd" UniqueName="Three" /> 
                <telerikGridView:GridViewDataColumn Header="Should be 1st" UniqueName="Four" /> 
            </telerikGridView:RadGridView.Columns> 
        </telerikGridView:RadGridView> 
  </Grid> 
</UserControl> 

namespace GridReorderIssue  
{  
    public partial class MainPage : UserControl  
    {  
        public MainPage()  
        {  
            InitializeComponent();  
            List<SampleClass> Data = new List<SampleClass>();  
            Data.Add(new SampleClass() { One = 1Two = "Two-1"Three = trueFour="Four-1" });  
            Data.Add(new SampleClass() { One = 2Two = "Two-2"Three = falseFour="Four-2" });  
 
            gdMain.ReorderColumns(3, 0);  
            gdMain.ReorderColumns(2, 1);  
 
            gdMain.ItemsSource = Data;  
        }  
    }  
 
    public class SampleClass  
    {  
        public int One { get; set; }  
        public string Two { get; set; }  
        public bool Three { get; set; }   
        public string Four { get; set; }  
    }  
}  
 

8 Answers, 1 is accepted

Sort by
0
Zarko Vorkapic
Top achievements
Rank 1
answered on 10 Nov 2009, 12:17 PM
I have the same issue.
0
Rossen Hristov
Telerik team
answered on 10 Nov 2009, 12:19 PM
Hi Randall Nelson,

Thank you for reporting this issue and please accept our apologies for the inconvenience it might have caused.

We would do our best to fix it as soon as possible. You account has been updated with Telerik Points for helping us identify this issue. Once again, please excuse us for the inconvenience.

All the best,
Ross
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Rossen Hristov
Telerik team
answered on 10 Nov 2009, 12:29 PM
Hello,

Update on the topic:

Actually, this behavior is normal since the call to ReorderColumns is made before columns have been generated. Since there are no generated columns, the cannot be reordered. If you call ReorderColumns after the columns have been generated then everything will work correctly. If you want to reorder the columns before the grid is bound simply add them in the desired order instead of calling the ReorderColumns method.

I hope this helps.

All the best,
Ross
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Randall Nelson
Top achievements
Rank 1
answered on 10 Nov 2009, 01:44 PM
Thanks for your answer.  But I don't think I understand.  In this sample project the columns have been setup in the XAML so it seems that they are already generated.  In my actual application I allow the user to save their layout.  In this application, I create the columns at runtime, then check to see if the user has saved a custom layout and apply it if so.

I still believe there is an issue with the Q3 build.  First, if I change the references on this sample project to the Q2 release, the reorder works as expected.  I didn't see anything in the Q3 release notes about a change to the behavior of ReorderColumns.

Second, I did a little more testing with the sample application.  I added a button and on the click event I reordered the columns (I removed the reorders from the constructor):

        private void btnReorder_Click(object sender, RoutedEventArgs e)  
        {  
            gdMain.ReorderColumns(3, 0);  
            gdMain.ReorderColumns(2, 1);  
        }  
 
So the application was up and running with data bound before I clicked.  Once I clicked, nothing happened.  I found that if I clicked twice, the second time the reorder worked.  I went back and put two sets of reorders in the constructor code and it also seems to make it work now:
        public MainPage()  
        {  
            InitializeComponent();  
            List<SampleClass> Data = new List<SampleClass>();  
            Data.Add(new SampleClass() { One = 1Two = "Two-1"Three = trueFour="Four-1" });  
            Data.Add(new SampleClass() { One = 2Two = "Two-2"Three = falseFour="Four-2" });  
 
            gdMain.ReorderColumns(3, 0);  
            gdMain.ReorderColumns(2, 1);  
 
            gdMain.ReorderColumns(3, 0);  
            gdMain.ReorderColumns(2, 1);  
 
            gdMain.ItemsSource = Data;  
        }  
 

So I can get the expected behavior if I call the same code twice.
0
Accepted
Hristo
Telerik team
answered on 11 Nov 2009, 10:01 AM
Hi Randall Nelson,

First I you to apologize. It was my mistake about the not generated columns. Indeed when they are set in xaml they are generated (after InitializeComponent method). There was a bug in our code that was accessing columns collection directly (instead of using display index). It has been fixed and the fix will be included in the latest internal build (this friday).
I've updated your telerik points.
As a side note we have added DisplayIndex property on GridViewColumn. You can use it to specify which column will be displayed first, second, etc. Instead of adding them in the correct order you can set their DisplayIndex to get the same effect. Also we have changed ReorderColumns method - before it was modifying the columns collection (by removing and adding the column), now it just change the display index for the column with DisplayIndex as first parameter).

I''m sorry for the caused inconvenience.
Let us know if you need more information.

Regards,
Hristo
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Randall Nelson
Top achievements
Rank 1
answered on 11 Nov 2009, 02:04 PM
Thanks for your reply.  I look forward to the fix in the next internal build.

But you mention that I should be able to use the display index.  Is that supposed to be working now - or does that also need a fix?  I am asking because I tried it, and it also does not seem to be working.  I altered the code from my sample project as shown below.  When I run the application, column four does show as the first column, but column three is not visible.  When I click on the column header for column for (like to sort by the column), then I get some really strange results.  The first two columns that are supposed to be hidden show up, and the rows don't display consistently (the first row seems correct, but the second and subsequent rows display different columns).

        public MainPage()  
        {  
            InitializeComponent();  
            List<SampleClass> Data = new List<SampleClass>();  
            Data.Add(new SampleClass() { One = 1Two = "Two-1"Three = trueFour="Four-1" });  
            Data.Add(new SampleClass() { One = 2Two = "Two-2"Three = falseFour="Four-2" });  
            Data.Add(new SampleClass() { One = 3Two = "Two-3"Three = trueFour = "Four-3" });  
            Data.Add(new SampleClass() { One = 4Two = "Two-4"Three = falseFour = "Four-4" });  
 
            gdMain.Columns["Four"].DisplayIndex = 0;  
            gdMain.Columns["Three"].DisplayIndex = 1;  
 
            //gdMain.ReorderColumns(3, 0);  
            //gdMain.ReorderColumns(2, 1);  
 
            gdMain.ItemsSource = Data;  
        }  
 
0
Hristo
Telerik team
answered on 11 Nov 2009, 02:29 PM
Hi Randall Nelson,

DisplayIndex will work with the latest internal build (ReorderColumns internally set DisplayIndex so It is the same problem) . You can set it in xaml too.

Regards,
Hristo
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Randall Nelson
Top achievements
Rank 1
answered on 17 Nov 2009, 02:48 PM
Thanks.  The 11/16 internal build fixed the issue.
Tags
GridView
Asked by
Randall Nelson
Top achievements
Rank 1
Answers by
Zarko Vorkapic
Top achievements
Rank 1
Rossen Hristov
Telerik team
Randall Nelson
Top achievements
Rank 1
Hristo
Telerik team
Share this question
or