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

How to hide columns

4 Answers 322 Views
VirtualGrid
This is a migrated thread and some comments may be shown as answers.
Luis
Top achievements
Rank 1
Luis asked on 13 Nov 2017, 02:02 PM

Dear Sirs,

I have been working with RadVirtualGrid for WPF and I have found a problem trying to change columns' visibility. I need to do it both from code and from xaml.
I would appreciate any help with it.

I'm working with DataProvider, if this info helps in anyway.

Thanks in advance,

4 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 14 Nov 2017, 05:13 PM
Hi Luis,

In order to hide or show given columns of RadVirtualGrid, you can define a custom DataProvder and alter its ItemProperties collection. For example, if you want to hide the first column, you can override the aforementioned property as follows.
public override IList<ItemPropertyInfo> ItemProperties
       {
           get
           {
               return base.ItemProperties.Skip(1).ToList();
           }
       }

By the time being, this property is not listed in the Custom DataProvider topic. We are currently working on improving the online help of the control, as well on providing an MVVM SDK Example that will include this functionality as well.

Let me know in case further assistance is needed.

Regards,
Stefan
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Luis
Top achievements
Rank 1
answered on 15 Nov 2017, 12:24 PM

Hello Stefan,

Thank you for your response.

I understand that that way will make me enable me to make a column invisible. However, how could a change a column's visibility during runtime, make it visible and invisible by clicking a button for example.

Thanks in advance,

0
Luis
Top achievements
Rank 1
answered on 16 Nov 2017, 11:51 AM
public class CustomDataProvider : DataProvider
   {
       private List<int> columnsToHide;
       public CustomDataProvider(IEnumerable source) : base(source)
       {
           columnsToHide = new List<int>();
       }
 
       public List<int> ColumnsToHide
       {
           get
           {
               return columnsToHide;
           }
 
           set
           {
               columnsToHide = value;
           }
       }
 
       public override IList<ItemPropertyInfo> ItemProperties
       {
           get
           {
               if (columnsToHide.Count > 0)
               {
                   List<ItemPropertyInfo> newItemProperty = new List<ItemPropertyInfo>();
                   for (int i = 1; i <= base.ItemProperties.Count; i++)
                   {
                       if (!columnsToHide.Contains(i))
                       {
                           ItemPropertyInfo it = base.ItemProperties[i-1];
                           newItemProperty.Add(it);
                           //newItemProperty = base.ItemProperties.ToList();
                       }
                   }
                   return newItemProperty.ToList();
               }
 
               return base.ItemProperties.ToList();
           }
       }
   }

I did this in order to solve my issue.
Thanks a lot for your help, Stefan.

0
Stefan
Telerik team
answered on 16 Nov 2017, 02:41 PM
Hello Luis,

I am happy that my suggestion helped you find a solution that meets your requirements.

Feel free to contact us again should you need any other assistance with our components.

All the best,
Stefan
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
VirtualGrid
Asked by
Luis
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Luis
Top achievements
Rank 1
Share this question
or