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

Set column IsVisbile to false take more than 10 seconds to hide a column

4 Answers 77 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Yimin
Top achievements
Rank 1
Yimin asked on 21 Oct 2011, 07:50 PM
Hi,

I have a radgridview. I render UI data distribution bars in each gridcell. I have hide column Icon on each column to allow user to hide a column by setting column IsVisible to false. But it takes a long time (>10 seconds) for the column to be hidden.
It is faster by setting column.Width to 0. But the column remains some positive width after setting the width to 0.

FYI, I turned off Row and Column virutalization on the radgridview and I have about 60 rows and 10 columns. Each cell is rendering with distribution bars.

Please let me know if this is a known issue or you have a resolution to this.

Thanks,
Yimin 

4 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 24 Oct 2011, 07:46 AM
Hello Yimin,

Generally, you need to work with the IsVisible property of the column. Setting its Width property is anything but recommended. 
Considering the long time to render, it is not expected especially when you have only 10 columns. Would you clarify which version of RadControls you are working with ? Could you provide more information about the way you are hiding the columns, is there anything more specific than just setting its IsVisible property to "False"/ "True". It would be great if you could share any code-snippet illustrating your approach.
 

Best wishes,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Yimin
Top achievements
Rank 1
answered on 24 Oct 2011, 06:18 PM

Hi,

Thanks for your attention. The Telerik controls we are using is of version: 2011.2.712.1040

I actually managed to hide the columns fast by setting both minimum width and width to 0. The way I am using it is kind of complicated: 1) we don't know the number of columns and column names until runtime; 2) The content of each row is dependent the value of one of each columns; 3) our columns and rows are styled to have some hidden delete buttons that only shows when mouse is over the row/column header.

1) To solve the 2 problems, I defined a CellTemplateSelector named MyCellTemplateSelector for each dynamic column I add at run time
2) To solve the 3rd problem, I have defined a header cell style for each column as the GetHeaderCellStyle method in the code snippet.
3) Please note that the button in the headercell style does not have event handler, since th xaml load can not have it. So I added a dummy column which would be the last column and add those event handlers when this column is loaded. This is hecky but this is the only way work since I figured radgridview fire events in this order: a) Grid_Loaded; 2) FirstColumn_Loaded; 3) Row_Loaded; 4) AllOtherColumn_Loaded -- it would be great that a) can be fired the last.

I suspect it is either 2) (adding the header cell style) or 3) adding the dummy column causing this. Please let me know if you have a solution for this.

public class MyCellTemplateSelector : DataTemplateSelector
 {
     public override DataTemplate SelectTemplate(object item, System.Windows.DependencyObject container)
     {
         bool isContinuous = false;
 
         GridViewCell cell = container as GridViewCell;
 
         PropertyInfo isContinousPropeteryInfo = item.GetType().GetProperty("IsContinuous");
 
         if (isContinousPropeteryInfo != null)
         {
             isContinuous = (bool)isContinousPropeteryInfo.GetValue(item, null);
         }
 
         StringBuilder CellTemp = new StringBuilder();
 
         CellTemp.Append("<DataTemplate ");
         ....
         CellTemp.Append(";assembly=myassembly'>");
 
         if (!isContinuous)
         {
             CellTemp.Append(string.Format("<local:MyCellDiscrete Margin='4 4 4 4' CellDistribution='{{Binding Mode=TwoWay, Path={0}}}'/>", BindingColumnName));
         }
         else
         {
             CellTemp.Append(string.Format("<local:MyCellContinuous Margin='4 4 4 4' CellDistribution='{{Binding Mode=TwoWay, Path={0}}}'/>", BindingColumnName));
         }
 
 
         CellTemp.Append("</DataTemplate>");
 
         return (DataTemplate)XamlReader.Load(CellTemp.ToString());
     }
 
     public string BindingColumnName { get; set; }
 }
 
  private Style GetHeaderCellStyle(string nodeId)
     {
         StringBuilder headerCellStyle = new StringBuilder();
 
         headerCellStyle.Append("<Style ");
         headerCellStyle.Append("xmlns='http://schemas.microsoft.com/winfx/");
         headerCellStyle.Append("2006/xaml/presentation' ");
         headerCellStyle.Append("xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' ");
         headerCellStyle.Append("xmlns:telerik='http://schemas.telerik.com/2008/xaml/presentation' ");
 
         headerCellStyle.Append("xmlns:GridView='clr-namespace:Telerik.Windows.Controls.GridView");
         headerCellStyle.Append(";assembly=Telerik.Windows.Controls.GridView' ");
         headerCellStyle.Append("TargetType='GridView:GridViewHeaderCell'>");
             headerCellStyle.Append("<Setter Property='Template'>");
                 headerCellStyle.Append("<Setter.Value>");
                     headerCellStyle.Append("<ControlTemplate>");
                     headerCellStyle.Append(string.Format("<Grid Name ='{0}' Margin='0' VerticalAlignment='Stretch'>", IdToColumnName(nodeId)));
 
                             headerCellStyle.Append("<Grid.ColumnDefinitions>");
                                 headerCellStyle.Append("<ColumnDefinition  Width='*' />");
                                 headerCellStyle.Append("<ColumnDefinition  Width='Auto' />");
                             headerCellStyle.Append("</Grid.ColumnDefinitions>");
                  
                             headerCellStyle.Append(string.Format("<TextBlock  Grid.Column='0' Text='{0}' VerticalAlignment='Center'/>", string.Empty));
 
 
                             headerCellStyle.Append("<Button Grid.Column='1' Name='HideButton'  Style='{StaticResource BorderlessButton}'  ");
                             headerCellStyle.Append("VerticalAlignment='Center' HorizontalAlignment='Right' Margin='2'  Opacity='0'>");
                                 headerCellStyle.Append("<Image Source='Delete_button.png'  Width='16' Height='16'/>");
                             headerCellStyle.Append("</Button>");
                         headerCellStyle.Append("</Grid>");
                     headerCellStyle.Append("</ControlTemplate>");
                 headerCellStyle.Append("</Setter.Value>");
             headerCellStyle.Append("</Setter>");
         headerCellStyle.Append("</Style>");
 
         return (Style)XamlReader.Load(headerCellStyle.ToString());
     }

Thanks,
Yimin

 

0
Maya
Telerik team
answered on 25 Oct 2011, 03:30 PM
Hello Yimin,

Firstly, using reflection to find the property name and the value for each time will surely slow down the performance. Please refer to our online documentation for a reference on how to get the item and its properties. Furthermore, you can find the column for each cell and get the property name as follows:

var propertyName = cell.Column.DataMemberBinding.Path.Path;

Secondly, why do you create the templates in the code-behind. You can define them in xaml as illustrated both in our online documentation and demos for a reference.
 

Greetings,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Yimin
Top achievements
Rank 1
answered on 25 Oct 2011, 05:53 PM
Hi Maya,

Thanks for replying. The way to get the propertyName would save some relection. Cool, thanks.

But the root cause should not be the reflection, since I don't expect you to re-rendering everything when setting the IsVisible to false. As I mentioned in the previous thread, I have dynamic columns which number of columns and their names can only be known at run time. Also each row would have different type of controls dependent on the value of one of the columns on each row. I sure have referenced to all related online demos, documents and samples. This is the solution I came up. The data is using the thin client datatable proposed by Telerik team. And the CellTemplateSelector is the way to tackle this problem. If you think there were other better solution, please kindly suggest some specfic relevant topcis or provide some sample. Otherwise, I might have to stay with my own solution.

Thanks,
Yimin

Tags
GridView
Asked by
Yimin
Top achievements
Rank 1
Answers by
Maya
Telerik team
Yimin
Top achievements
Rank 1
Share this question
or