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

Settings GridViewColumn.DisplayIndex Breaks GridViewColumnGroup.Header Showing

3 Answers 44 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jimmy
Top achievements
Rank 1
Jimmy asked on 14 Nov 2020, 10:15 PM

Hello

In a release of WPF after 2015.2.728 (up to and including 2020.2.617) the ability to programatically set the DisplayIndex of a GridViewColumn was broken, in what seems to be a bug (it used to work fine, and I'm not sure what behaviour you could achieve with this bug in place).  I haven't pinpointed the release, as a lot of releases have happened during that time!

I've attached a simple example which demonstrates this bug, you just have to change the boolean constant in the code behind file from `false` to `true`, and you'll see that the group header no longer shows.  If you go back to release 2015.2.728 then this works, but now it only works if you set DisplayIndex to -1 (anything else causes an argument exception, as there's a mismatch to the number of columns, which makes sense).  If you don't have the header group then you can obviously change the DisplayIndex as required, but as soon as you do, it breaks the header grouping.

I'd post the code solution if I could, but it's pretty simple, you don't even need the public class in my code behind, that's there just to make the column group header obvious.

 

Thanks!

3 Answers, 1 is accepted

Sort by
0
Jimmy
Top achievements
Rank 1
answered on 14 Nov 2020, 10:17 PM
Also, much of the XAML isn't required either, again it's just to make it obvious where the column group header is.  You can trim it down to just the RadGridView if you like.
0
Accepted
Vladimir Stoyanov
Telerik team
answered on 18 Nov 2020, 12:49 PM

Hello Jimmy,

Thank you for the shared pictures. 

I was able to replicate the same result on my end and I have logged a new item in our feedback portal: GridView: ColumnGroup is not displayed when the Columns DisplayIndex is set when they are initialized. I have also added some telerik points to your account as a thank you for bringing this to our attention.

As a workaround, for the moment, you can set the DisplayIndex of the columns after they are created. Here is what I have in mind:

public partial class MainWindow : Window
    {
        private const string ColumnGroupName = "MyColumnGroup";
        public MainWindow()
        {
            InitializeComponent();

            var displayIndex = -1;
            this.RadGridView1.Columns.AddRange(
                new[]
                {
                    new Telerik.Windows.Controls.GridViewColumn
                    {
                        ColumnGroupName= ColumnGroupName,
                        Header = "Column A",
                    },
                    new Telerik.Windows.Controls.GridViewColumn
                    {
                        ColumnGroupName= ColumnGroupName,
                        Header = "Column B",
                    },
                    new Telerik.Windows.Controls.GridViewColumn
                    {
                        ColumnGroupName= ColumnGroupName,
                        Header = "Column C",
                    }
                }

            );

            foreach (var col in this.RadGridView1.Columns)
            {
                col.DisplayIndex = ++displayIndex;
            }

            var columnGroup = new GridViewColumnGroup
            {
                Name = ColumnGroupName,
                Header = "Test"
            };
            this.RadGridView1.ColumnGroups.Add(columnGroup);
            
        }
    }

I hope you find this helpful.

Regards,
Vladimir Stoyanov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Jimmy
Top achievements
Rank 1
answered on 18 Nov 2020, 12:56 PM
Thanks Vladimir, that's very much appreciated
Tags
GridView
Asked by
Jimmy
Top achievements
Rank 1
Answers by
Jimmy
Top achievements
Rank 1
Vladimir Stoyanov
Telerik team
Share this question
or