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

Show/Hide columns using IsVisible is slow

2 Answers 179 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Pieter Jan Verfaillie
Top achievements
Rank 1
Pieter Jan Verfaillie asked on 08 Jan 2013, 03:51 PM
Hi, 


I'm using the gridview to show items that are defined like following code:

public class GridLine
    {
        public string Key { get; set; }
        public List<Year> Years { get; set; }
    }
 
public class Year
    {
        public string Code { get; set; }
        public int TotalValue { get { return Months != null ? Months.Sum(m => m.Value) : 0; } }
        public List<Month> Months { get; set; }
    }
 
public class Month
    {
        public string Code { get; set; }
        public int Value { get; set; }
    }

Because the list of years and the list of months are hierarchically and have variable lengths, the columns for these items must be generated on data load of the datagrid. The bindings are also defined in this part.

The desired behavior of the year column and the corresponding month columns is like this:
  • when the year column is visible, the month columns aren't visible
  • when doubleclicked on the header of the year column, the month columns are shown and the year column is hidden. 
  • vice versa...

I'm using this code to obtain this:

private void TestGridDataLoaded(object sender, EventArgs e)
{
    var items = (List<GridLine>)TestGrid.ItemsSource;
    if (items == null || items.Count == 0) return;
 
 
    // Generate columns for hierarchical years and months.
    for (int yearCounter = 0; yearCounter < FixedNumberOfYears; yearCounter++)
    {
        var year = items[0].Years[yearCounter];
        var yearColumn = new GridViewDataColumn
            {
                Tag = year.Code,
                DataMemberBinding = new Binding(string.Format("Years[{0}].TotalValue", yearCounter)),
            };
        yearColumn.Header = CreateColumnHeaderLabel(yearColumn, year.Code);    // creates a double clickable header to toggle visibility
 
        _gridColumns.Add(yearColumn, new List<GridViewDataColumn>());
        TestGrid.Columns.Add(yearColumn);
 
        for (var monthCounter = 0; monthCounter < FixedNumberOfMonths; monthCounter++)
        {
            var month = year.Months[monthCounter];
            var monthColumn = new GridViewDataColumn
            {
                IsVisible = false,
                Header = CreateColumnHeaderLabel(yearColumn, month.Code, true),
                DataMemberBinding = new Binding(string.Format("Years[{0}].Months[{1}].Value", yearCounter, monthCounter))
            };
 
            _gridColumns[yearColumn].Add(monthColumn);
            TestGrid.Columns.Add(monthColumn);
        }
    }
}
 
private System.Windows.Controls.Label CreateColumnHeaderLabel(GridViewDataColumn yearColumn, string content, bool isMonth = false)
{
    var label = new System.Windows.Controls.Label
    {
        Content = content,
        Tag = yearColumn, Foreground = new SolidColorBrush( isMonth ? Colors.Yellow : Colors.White)
    };
 
    label.MouseDoubleClick += ToggleColumnsVisibility;
 
    return label;
}


Now, all this works fine, except for the showing and hiding of the columns. The performance of this action is quite slow. when a dozen columns must be hidden (IsVisible=false) and a dozen hidden columns must be shown (IsVisible=true), it takes some seconds. 

Can anyone explain to me how this showing and hiding using the  IsVisible property works and if there are ways to reduce the rendering time of these actions?

I've added a screenshot of the real life project to this thread. The project is much more complex then the code samples above because it uses converters, custom celltemplates, custom celledittemplates... when creating the columns for month and year. This probably also slows down the rendering.

Best regards, 
Pieter Jan Verfaillie

2 Answers, 1 is accepted

Sort by
0
Yoan
Telerik team
answered on 11 Jan 2013, 12:35 PM
Hello Pieter,

As it turns out, we are not aware with such performance issue when using the IsVisible property.

Indeed you are quite right, if you have a complex scenario, it is possible that there is something specific which causes the reported issue.

So, would it be possible to send a simple runnable project demonstrating the issue? You can take a look at this blog post for a reference on how to isolate a problem in a sample project. We will debug it on our side in order to find the cause.

Regards,
Yoan
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Pieter Jan Verfaillie
Top achievements
Rank 1
answered on 22 Jan 2013, 02:57 PM
Hi Yoan, 


I have a sample project ready that demonstrates the issue.

However my company holds the license for the Telerik controls and I haven't got hold on the account yet. 
I'm expecting to be able to log a support issue. 


Best regards, 
Pieter Jan
Tags
GridView
Asked by
Pieter Jan Verfaillie
Top achievements
Rank 1
Answers by
Yoan
Telerik team
Pieter Jan Verfaillie
Top achievements
Rank 1
Share this question
or