This is a migrated thread and some comments may be shown as answers.
GridViewDataColumn.IsVisible
59 Answers 877 Views
This is a migrated thread and some comments may be shown as answers.
Eric Zeng
Top achievements
Rank 1
Eric Zeng asked on 16 Mar 2010, 08:54 AM
<Telerik:GridViewDataColumn Header="test" IsVisible=="{Binding Path=tName, Converter={StaticResource tNameToVisibilityConverter}}"  />


When I using this way to decide whether displaying column or not, the error happened.
But I have used this way in other places for many times, it only has problem when using on GridViewDataColumn .
So I want to ask you, can we use this way here?



59 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 16 Mar 2010, 09:02 AM
Hi,

You cannot bind column properties since Binding is supported only for FrameworkElement – grid columns are plain DependencyObjects.

Sincerely yours,
Vlad
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Eric Zeng
Top achievements
Rank 1
answered on 16 Mar 2010, 10:28 AM
thanks:)
0
Rodrigo Rodriguez
Top achievements
Rank 1
answered on 25 Jun 2010, 10:54 PM
You can use this mechanism. In your ViewModel you would set ColumnsToHide to a string containing columns names separated by a comma.

using System.Windows; 
 
namespace Helpers 
    public class ColumnHiderBinder 
    { 
        public static readonly DependencyProperty ColumnListProperty = 
            DependencyProperty.RegisterAttached("ColumnList"typeof(string), 
            typeof(string), new PropertyMetadata(OnColumnListChanged)); 
 
        public static string GetColumnList(DependencyObject d) 
        { 
            return (string)d.GetValue(ColumnListProperty); 
        }         
         
        public static void SetColumnList(DependencyObject d, string value) 
        { 
            d.SetValue(ColumnListProperty, value); 
        }          
         
        private static void OnColumnListChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) 
        { 
            if (!(d is RadGridView)) return
 
            var obj = ((RadGridView) d); 
 
            foreach (var item in ((string) e.NewValue).Split(new [] {','})) 
            { 
                obj.Columns[item].IsVisible = false
            } 
        } 
    } 
 


And then in your XAML:

      
<RadGridView  Helpers:ColumnHiderBinder.ColumnList="{Binding ColumnsToHide}" > 


0
Kaka
Top achievements
Rank 1
answered on 30 Jun 2010, 11:21 AM
Hello Vlad,
I am currently trying out your WPF RadGrid control, and first of all I really have to say great job to you all. It's a really good product compared to all the others out there.
However, I couldn't help it to notice your statement about DataBinding on DependencyObjects and I really cannot figure it out. Could you please be so kind as to helping me out on this one.
First lets look at this post by Mr. Nikolay Atanasov. In it, Telerik proudly announces native Silverlight 4 support of it's controls. In the product list provided, there is your RadControls suit for SL4 (it's the last one with the red rectangle around it). The post is dated to March 18, 2010. Your own post, in which you say that there is no DataBinding on DependencyObjects is dated to March 16, 2010. I am guessing that 2 days is not such a long time to turn things around so dramatically. Having said that, I am guessing that you probably had native support for SL4 long before the announcement day on March 18 (please correct me if I'm wrong).
By now your statement has been that your RadControls have native support for SL4, and that DataBinding is not possible on DependencyObjects. To be honest I'm really confused here. A long time ago I've read this post by Mr. Shawn Wildermuth about some of the changes in SL4. As he says, DataBinding is actually now available on DependencyObjects. When I read your post Vlad, I sat down and opened Visual Studio. Started out a new project and as it turns out, in SL4 the Binding has really moved out to the DependencyObject contrary to SL3 in which it really was in the FrameworkElement.
My question would be as follows: How can you say your RadControls have native SL4 support, when you guys don't even know the difference between SL3 and SL4?
0
Milan
Telerik team
answered on 30 Jun 2010, 12:29 PM
Hello Kaka,

I am sure that Vladimir Enchev had Silverlight 3 in mind when he made that comment. Binding on DependecyObject is indeed supported in Silverlight 4.

Excuse us for the misunderstanding. 


Kind regards,
Milan
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Juan
Top achievements
Rank 1
answered on 26 Jul 2010, 12:09 PM
Can anybody give me an example how to use visibility binding in RadGridView ? I need to hide some rows in it.
0
Vlad
Telerik team
answered on 26 Jul 2010, 12:20 PM
Hello Juan,

 This thread is related to columns visibility - can you elaborate a bit more on your scenario? Generally messing with rows visibility is not recommended since the grid virtualization will use it and you may get problems with such approach. It will be better if you filter your items before binding the grid or use the grid filtering to hide some of them.

Regards,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Jaroslav Půbal
Top achievements
Rank 1
answered on 26 Aug 2010, 10:59 AM
So back to the top question.
Why dont work databinding on GridViewDataColumn on IsVisible in Silverlight4.

 

 

 

<Controls:GridViewDataColumn DataMemberBinding="{Binding Rusky}" Header="Russian" IsReadOnly="True" IsVisible="{Binding ColumnRuskyVisible}"/>

 

0
Maya
Telerik team
answered on 30 Aug 2010, 10:03 AM
Hi Jaroslav Půbal,

You can easily use a Binding to the IsVisible property of the column. I am sending you a sample project illustrating that functionality. Following the scenario in the sample application, once you check the CheckBox in the bottom, the visibility of the second column will be changed.
I hope that helps.
 

Sincerely yours,
Maya
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Rodrigo Rodriguez
Top achievements
Rank 1
answered on 30 Aug 2010, 08:16 PM
Maya, this is a new feature, right? I have noticed in the updated Telerik assemblies. So the ColumnHiderBinder is not necessary anymore.
0
Vlad
Telerik team
answered on 31 Aug 2010, 07:06 AM
Hello,

 This is now supported by the Silverlight (4) framework itself (unlike Silverlight 3) - you can remove old hacks. 

Regards,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Jaroslav Půbal
Top achievements
Rank 1
answered on 31 Aug 2010, 10:31 AM
Hi Maya,
I finally figured out why column visibility does not work and how to simulate.
Dont know if it Telerik or SL4 bug.

Based on your attachment I change in MainPage.xaml two lines.

 

<telerik:GridViewDataColumn IsVisible="{Binding IsChecked, ElementName=CheckBox1}" ... 

 

<CheckBox x:Name="CheckBox1" />

 

  1. Now I expected that after application start CheckBox is unchecked and column is invisible. But column is visible.
  2. When checking and unchecking I expect column is hiding and showing. But nothing happens unless I select column with mouse.

MainPage.xaml

<UserControl x:Class="BindingToIsVisible.MainPage"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
             xmlns:my="clr-namespace:BindingToIsVisible"
             mc:Ignorable="d" d:DesignHeight="700" d:DesignWidth="700">
    <UserControl.Resources>
        <my:MyViewModel x:Key="MyViewModel"/>       
    </UserControl.Resources>
    <Grid x:Name="LayoutRoot" 
          Background="White" 
          DataContext="{StaticResource MyViewModel}">
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
         
        <telerik:RadGridView Grid.Row="0" 
                             Name="clubsGrid" 
                             ItemsSource="{Binding Clubs}"
                             AutoGenerateColumns="False"                            
                             Margin="5">
            <telerik:RadGridView.Columns>               
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}"/>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Established}"
                                            Header="Est." 
                                            IsVisible="{Binding IsChecked,  ElementName=CheckBox1}"
                                            DataFormatString="{}{0:yyyy}"/>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding StadiumCapacity}" 
                                            Header="Stadium" 
                                            DataFormatString="{}{0:N0}"/>
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>
          
        <StackPanel Grid.Row="1" Orientation="Horizontal">
            <TextBox Text="Click here to hide the last column" />
            <CheckBox x:Name="CheckBox1"  />
        </StackPanel>
    </Grid>
</UserControl>
0
Maya
Telerik team
answered on 02 Sep 2010, 09:59 AM
Hi Jaroslav Půbal,

Following up your scenario, you need to set the Binding as follows:

<CheckBox x:Name="CheckBox1" IsChecked="{Binding Columns[2].IsVisible,  
                                      ElementName=clubsGrid, Mode=TwoWay}"
/>


Regards,
Maya
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Jaroslav Půbal
Top achievements
Rank 1
answered on 02 Sep 2010, 10:30 AM
Hi Maya,
thank you for answer.
You solution works great. Except one case. When I need show/hide two columns.

<telerik:GridViewDataColumn Header="system column 1" IsVisible="{Binding IsChecked, ElementName=CheckBox1}" ... 

<telerik:GridViewDataColumn Header="system column 2" IsVisible="{Binding IsChecked, ElementName=CheckBox1}" ... 

<CheckBox x:Name="CheckBox1" Header="System columns visible"/>



Is this behaviour expected? Will you fix this bug or this is by design right behaviour.
Thank for answer.
0
Jarred Froman
Top achievements
Rank 1
answered on 02 Sep 2010, 06:36 PM
How would you do this via code-behind?  Normally, you could use the SetBinding function, but since the GridViewDataColumn doesn't inherit from the FrameworkElement, this function isn't available.

Thanks,
-Jarred Froman
0
Maya
Telerik team
answered on 07 Sep 2010, 02:16 PM
Hello Jaroslav Půbal,

On examining your requirements, another - and probably the most appropriate solution for that case - came up. What needs to be done here is to set the "Source" Property on defining the Binding of the IsVisible Property of the column. Thus once you set your ViewModel as a Resource, you will be able to use it afterwards like follows:

<UserControl.Resources>
      <my:MyViewModel x:Key="MyViewModel"/>    
</UserControl.Resources>
 
<telerik:RadGridView.Columns>              
      <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}"/>
      <telerik:GridViewDataColumn DataMemberBinding="{Binding Established}"
Header="Est."
                   IsVisible="{Binding IsColumnVisible, Source={StaticResource MyViewModel}}"                                                                                   
                 
DataFormatString="{}{0:yyyy}"/>
<telerik:GridViewDataColumn DataMemberBinding="{Binding StadiumCapacity}"
Header="Stadium"
                   IsVisible="{Binding IsColumnVisible, Source={StaticResource MyViewModel}}"
DataFormatString="{}{0:N0}"/>
</telerik:RadGridView.Columns>

<CheckBox x:Name="CheckBox1"
        IsChecked="{Binding IsColumnVisible, Source={StaticResource MyViewModel},         Mode=TwoWay}"/>

Where "IsColumnVisible" is a property defined in the ViewModel.
Thus both columns as well as the CheckBox are aware where exactly to find that property - the MyViewModel.
I am sending you a sample project illustrating the proposed solution.


Regards,
Maya
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Jaroslav Půbal
Top achievements
Rank 1
answered on 07 Sep 2010, 02:59 PM
Thank you for your interest and sample code.

I already discover this solution. It is little strange that ElementName= no working, but it doesnt matter.
I add extra property on ViewModel even I never touch it from ViewModel code.

Maybe this is SilverLight 4 bug :-)

Thank you for superb support!
0
Sam
Top achievements
Rank 1
answered on 12 Oct 2010, 01:02 AM
Maya and Vlad,

I am having the same exact problem as Jaroslav, where a binding on GridViewColumn.IsVisible is only triggered when a cell within that column is selected.  I am currently using Q2 2010 (no service packs), and I need to know how to combat the problem.  Has telerik been able to reproduce this issue?  Has it been fixed in recent service packs?

Looking forward to your response,
Sam
0
Maya
Telerik team
answered on 14 Oct 2010, 02:08 PM
Hello Sam,

The fact that the ElementName is not working as expected in this case is due to some limitations in the Framework. Is it not appropriate for you to use the approach with setting the Source property of the Binding ? Please, share more details about your requirements, so that I could provide you with a proper solution.
 

Regards,
Maya
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Sam
Top achievements
Rank 1
answered on 14 Oct 2010, 04:06 PM
The parent page has it's datacontext to a viewmodel that is set by a viewmodellocator.  Therefore, it is not a static resource.  The grid on the page does not have a datacontext, so therefore any data bindings on grid (and gridviewcolumn) properties should be bound to the view model on page.datacontext.

Yet when i setup a binding on IsVisible, the property is not honored *until i click within a cell of that column*.  At that point, the databinding starts behaving normally.  This tells me two things:

1. my binding is bound to the correct viewmodel property, because after clicking in the cell, it works as expected.
2. this is not the elementname problem you speak of, because I am not using it here at all.  

--Sam
0
Maya
Telerik team
answered on 20 Oct 2010, 07:50 AM
Hello Sam,

Based on the previous post, I got the impression that you are experiencing the same issue as the others with setting the ElementName binding property. How exactly are you setting the binding to IsVisible Property of the column ? Do you change it by checking/ unchecking a CheckBox as mentioned here before ? Any relevant code-snippet would be helpful.
 

Kind regards,
Maya
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Alexey Oyun
Top achievements
Rank 1
answered on 29 Oct 2010, 12:09 PM
Hi,

If you change example solution you have provided, and change bindning in checkbox to
<telerik:GridViewDataColumn DataMemberBinding="{Binding Established}"
                                   Header="Est."
                                   IsVisible="{Binding ElementName=LayoutRoot, Path=DataContext.IsColumnVisible}"
                                   DataFormatString="{}{0:yyyy}"/>

Binding won't work, right now I have created resource just to be able to hide column
:(

Alexey
0
kulashaker
Top achievements
Rank 1
answered on 03 Nov 2010, 01:58 AM
I am having the same problem:

When binding "IsVisible" property in the following way:

<telerik:GridViewDataColumn
Header="Pecent"  
DataMemberBinding="{Binding PercentDouble}"  
IsVisible="{Binding Path=DataContext.ShowPercentageColumn, ElementName=LayoutRoot, Mode=OneWay}" />


It does not work unless the user has clicked in the Column once. After the user clicks on the column, it work nicely.

Has anybody found a solution to this problem?

Thanks
Bruce
0
Devon
Top achievements
Rank 1
answered on 05 Nov 2010, 12:05 AM
Try making the binding Two way:

IsVisible="{Binding Path=DataContext.ShowPercentageColumn, ElementName=LayoutRoot, Mode=TwoWay}"

This should fix the problem.

If you don't have any binding Mode Like :
IsVisible="{Binding Path=DataContext.ShowPercentageColumn, ElementName=LayoutRoot}"

then it will use the default binding mode for that property, I assume that IsVisible's default binding mode is OneWay, which is why it is not working for that scenario either.

If you want to programatically change the value of a bound value and have the UI update itself automatically (without any user interaction on the UI), then you need to make the Mode=TwoWay. 

Hope this helps.
0
kulashaker
Top achievements
Rank 1
answered on 05 Nov 2010, 02:02 AM
Hi Devon, thanks for your reply, but it did not fix the problem. It reacts the same for both OneWay and TwoWay modes. User must click on the column for it to work as expected.
0
Maya
Telerik team
answered on 08 Nov 2010, 05:43 PM
Hello kulashaker,

Using the ElementName binding is not as reliable as expected and unfortunately it does not always provide the desired result. One possible approach would be to define a Resource and use it as a StaticResource in the Binding as demonstrated above. 
Another technique is to wrap the RadGridView in a custom UserControls that exposes a property responsible for the column's visibility. I am sending you a sample project illustrating the proposed solution.
 

Kind regards,
Maya
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Dave Clark
Top achievements
Rank 1
answered on 04 Jan 2011, 03:58 PM
I have the same problem as Sam, was this ever resolved ?.

Basically I am binding to a viewmodel, on that viewmodel is a bool property which i bind to IsVisible property on the GridViewDataColumn.
This bool property can change, depending on what mode the grid is in, and hence columns should hide/show depending on this.
When the datagrid is first shown, the binding is not initiated and only gets initiated when I click in the column.
I know this because I can change the binding to an incorrect property and I get a binding error in debug output (only when i click in the column), if I don't click in the column, i get no binding error, which tells me that the binding is not getting initialized until you click in the column.

Is there any solution to this ?
I want columns to be hidden/shown on first entry, clicking in the column to fire bindings is just ..... well ....wrong.

Many thanks

Dave
0
Geoff
Top achievements
Rank 1
answered on 19 Jan 2011, 11:04 PM
Same problem here. I have a viewmodel that is the datacontext for the UserControl that the RadGridView is located in, and a bool property for each column. In the XAML, the IsVisible property on each of these columns is bound to the aforementioned properties in the viewmodel.

I have also noticed that clicking the cells seems to "activate" the binding, and after that point the column shows or hides appropriately based on the value of the property.

This seems like a bug to me. We were using the Microsoft DataGrid which didn't allow binding the Visibility property, so I was hoping that when we made the change to use the RadGridView, we would no longer have to set it programmatically.

Thanks,
Geoff
0
Dave Swersky
Top achievements
Rank 1
answered on 23 Jan 2011, 04:09 PM
I'm also having this problem.  I can't use a static resource because I'm using a viewmodellocator.  I will need to show/hide columns in many places throughout the application I'm working on.  I hope there is a clean workaround that doesn't require a static context resource.
0
Terry Foster
Top achievements
Rank 1
answered on 09 Mar 2011, 02:44 AM
I just found and read through this entire thread, as I am desiring and expecting similar behavior as many here.  I noted how at no point is Telerik taking any responsibility for this issue - only workarounds.  And now more than a month has passed with no response.  What is the deal?  I, too, cannot define a static resource as I'm using a 'view model locator' concept as well.  And we shouldn't have to!  Has a bug report or feature request been opened for this?  I'm sure many here would quickly vote for this.

Terry
0
Pavel Pavlov
Telerik team
answered on 15 Mar 2011, 10:29 AM
Hi Terry Foster,

Columns in RadGridView for Silverlight   are plain dependency objects  rather than visual elements. Altering the behavior of RadGridView  so that such bindings become possible would inevitably introduce a lot of breaking changes and inconsistent  behavior with previous versions making upgrades to newer versions a pain for lots of our customers. This is the reason we recommend the solutions / workarounds mentioned before.

Regards,
Pavel Pavlov
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
John
Top achievements
Rank 1
answered on 17 Mar 2011, 08:41 PM
I'm currently using the 2010Q3 Silverlight controls. The following workaround worked for me:

        private void RadGridView_Loaded(object sender, RoutedEventArgs e)
        {
            var gridView = (GridViewDataControl)sender;
 
            var originalCurrentColumn = gridView.CurrentColumn;
            foreach (var column in gridView.Columns)
                gridView.CurrentColumn = column;
            gridView.CurrentColumn = originalCurrentColumn;
        }

It does seem that Telerik could make this happen by default, if they haven't already fixed it in the latest version.
0
Brian
Top achievements
Rank 1
answered on 06 May 2011, 04:59 PM
So, binding the IsVisible property to a property in a view model is not possible?

This seems like a MAJOR oversight in the control.
0
Iurii
Top achievements
Rank 1
answered on 19 May 2011, 01:27 AM
I completely agree. It defies the purpose of using XAML.
0
John
Top achievements
Rank 1
answered on 19 May 2011, 02:35 AM
I totally agree also. However, notice that in my previous response, I have a very simple and general workaround that does allow you to bind the IsVisible property to a property in a view model.
0
Brian
Top achievements
Rank 1
answered on 19 May 2011, 03:00 PM
John-

Are you referring to your post on March 17th?  I don't see anything in that post regarding binding to IsVisible but if you are just saying that this could be done in combination with the code-behind, then I understand.

Tks.
0
John
Top achievements
Rank 1
answered on 19 May 2011, 08:41 PM
Correct. In the version of the RadControls (2010Q3sp1) and Silverlight (4) that I was using, I was able to bind to the IsVisible property of the <telerik:GridViewDataColumn>. However, the bindings didn't "take effect" until the user clicked on one of the columns (or something similar). The code-behind I provided just helped the Telerik control to do the right thing upon loading.
0
Brian
Top achievements
Rank 1
answered on 19 May 2011, 09:10 PM
Ah, ok.  I'll give it a shot.  I have had no luck binding the IsVisible property to my view model so I'm skeptical but it's worth giving it a shot.

Tks.
0
Prakash
Top achievements
Rank 1
answered on 22 May 2011, 08:20 PM

We had a similar problem the RadTreeListView (based on the RadGridView) when binding a column's GridViewDataColumn.IsVisible to a property in the ViewModel. A workaround was to create a subclass of the RadTreeListView, add a dependency property that in turn was bound to the ViewModel's property, and use the dependency property's property change callback to programmatically update the column's IsVisible property.

BTW, setting a column's IsVisible to False within the xaml to initially hide the column was not working correctly. So we had to remove this from the xaml and programmatically set the IsVisible value to false within an override of OnApplyTemplate in the treeview subclass.


Combining the two is working great for us.

public class CustomTreeListView : RadTreeListView
    {
        public CustomTreeListView() : base()
        {
        }
  
        #region DTDColumnVisible Dependency Property
  
        /// <summary>
        /// Dependency property used for changing the DTDColumn visibility. Binding directly to GridViewDataColumn.IsVisible 
        /// property does not work. Workaround.
        /// </summary>
        public bool DTDColumnVisible
        {
            get { return (bool)this.GetValue(DTDColumnVisibleProperty); }
  
            set { SetValue(DTDColumnVisibleProperty, value); }
        }
  
        public static readonly DependencyProperty DTDColumnVisibleProperty = DependencyProperty.Register(
            "DTDColumnVisible", typeof(bool), typeof(CustomTreeListView), new PropertyMetadata(false, new PropertyChangedCallback(OnDTDColumnVisibleChanged)));
  
        private static void OnDTDColumnVisibleChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
        {
            // Update the DTDColumn visibility
            CustomTreeListView treelistview = obj as CustomTreeListView;
            if (treelistview != null)
                treelistview.Columns["DTDColumn"].IsVisible = (bool)args.NewValue;
        }
  
        #endregion DTDColumnVisible Dependency Property
  
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
  
            this.Columns["DTDColumn"].IsVisible = false;
        }
    }
0
Paul McNamara
Top achievements
Rank 1
answered on 21 Jun 2011, 12:00 PM
I'm struggling with this too but I'm creating my columns programmatically and the bindings too.

I have the latest controls and it doesn't seem to be picking up the bindings for IsVisibleProperty, IsReadOnlyProperty or HeaderProperty at all. I've tried hooking into the Loaded event like John suggested but it doesn't seem to make a difference. I'm using BindingOperations.SetBinding() to set the bindings on the GridViewDataColumn instance.

I've noticed that there is an IsReadOnlyBinding which I can work with but I still need to be able to bind the visibility and header to my viewmodel. If it's just not possible I'll probably do something the the MVVM Lite messaging framework.
0
Matthias
Top achievements
Rank 1
answered on 03 Jan 2012, 03:23 PM
I absolutely agree that this is a major flaw!
In WPF it works as expected, so why shall it be a breaking change to fix this BUG?

edit: When I set IsVisible to False via ViewModel and click a cell within that column the column disappears and the program crashes...
0
Kelly
Top achievements
Rank 1
answered on 13 Jan 2012, 06:32 PM
I'm using V2011.3.1227.1040 of the gridview and SLR5. When I bind IsVisible to a view model, the binding is simply ignored. A definite answer how to make this work would be greatly appreciated.

KO
0
Tim
Top achievements
Rank 1
answered on 13 Jan 2012, 08:55 PM
Same problem for me also, but I have the complication of using the HierarchyChildTemplate and hiding columns in both the parent and child grid.  John's workaround worked for me (putting the Loaded event handler on both the parent and child grids), but still seems like the IsVisible should just work like other controls.

0
JJ Loubser
Top achievements
Rank 1
answered on 10 Feb 2012, 09:54 AM
if the isVisible field is not working, take it out, do it for youre customers, please it is confusing...
0
Juliana
Top achievements
Rank 1
answered on 24 Feb 2012, 02:40 PM
Hi there,

Could anybody help me to set binding for GridViewDataColumn.IsVisible property from code behind?

Thanks
0
Kelly
Top achievements
Rank 1
answered on 24 Feb 2012, 04:31 PM
Hi Juliana,

Here's what worked for me. The xaml binding is ignored, so I set bindings in the Loaded event for the page the grid is in. In my view model (based on INotifyPropertyChanged, naturally), I have one boolean property for each column in the grid, and the names of these properties correspond to the UniqueName fields for each column, for example, IsCol1Visible, IsCol2Visible, etc.

In the loaded event I set the bindings like this:

Binding b;
 
foreach (GridViewBoundColumnBase c in grid.Columns)
{
    b = new Binding(string.Format("Is{0}Visible", c.UniqueName));
    b.Mode = BindingMode.TwoWay;
    b.Source = View;
    BindingOperations.SetBinding(c, GridViewDataColumn.IsVisibleProperty, b);
}

I don't know if this is a good way, or if there is a better way, but this certainly works. Hope that helps!

Kelly
0
Juliana
Top achievements
Rank 1
answered on 27 Feb 2012, 01:04 PM
Hi Kelly,
Thanks a lot! This code works like a charm!
Juliana
0
guillekang
Top achievements
Rank 1
answered on 04 May 2012, 07:42 AM
  Hi.  I am currently using IsVisible property bound to a property of my view model.

1.) Create a DataContextProxy class,  as in : 
http://forums.silverlight.net/post/539919.aspx 

i have used this proxy class in SL4 and SL5 and it works pretty well when using mvvm.

2.) Add a resource to your user control:
<myns:DataContextProxy x:Key="DCProxy/>

3.) Bind the IsVisible property to a property of your view model:

  <telerik:GridViewDataColumn
                        Width="120"
                        DataMemberBinding="{Binding MyAdress, Mode=TwoWay}"
                        IsVisible="{Binding DataSource.IsMyAddressVisible, Source={StaticResource DCProxy}}">

4.) Remeber to call PropertyChanged when IsMyAddressVisible  changes its value in your view model.

Hope it helps,


Guillermo
0
John
Top achievements
Rank 1
answered on 19 Jul 2012, 01:06 PM
If you've upgraded to the latest silverlight you can go up the tree until you reach outside the grid and grab the data context that way.  

IsVisible="{Binding Path=DataContext.IsColumnVisible, RelativeSource={RelativeSource FindAncestor, AncestorType=Border}}"
0
Bob
Top achievements
Rank 1
answered on 03 Aug 2012, 04:55 PM
Hello,

We are using the 2012.2.725.1050 build of SL controls. Is John's code behind workaround still the only way to get this to work. We require to bind this directly within the XAML without the need for code behind.  Any update?

thx...vsdotnetguy
0
Chethan
Top achievements
Rank 1
answered on 17 Oct 2012, 11:17 AM
Hi Bob,
Even we are using the same 2012.2.725.1050 build with SL5, and I am able to set the IsVisible property directly 
from XAML and it works with no issues.

Telerik Team,

Binding from ViewModel to set IsVisible property of a GridVIewDataColumn doesn't work, 
even the workarounds provided by many guys here to create a Static Resource doesn't work because, 
we cannot create a parameterless constructor, without which I cannot access myViewModel class from XAML.

Can you guys provide us with a solution??
Thnx
Chethan
0
Tingting
Top achievements
Rank 1
answered on 12 Nov 2012, 10:55 AM
Hello,   i have a problem with RadGridView. In my GridViewDataColumn, i cant use DataMemberBinding for binding with a another element (textbox1). The column TEST is always null.
<TextBox Height="23" Name="textBox1" Width="120" Text="test"  />
 
 <telerik:RadGridView x:Name="dgrDetailsFacture"
      ItemsSource="{Binding ElementName=dgrFacture,Path=SelectedItem.GrpLigneFacture}"      
      IsSynchronizedWithCurrentItem="true"
     CanUserResizeColumns="False" >
                        <telerik:RadGridView.Columns>
                             <telerik:GridViewDataColumn
                TextAlignment="Center" IsReadOnly="True"
                                DataMemberBinding="{Binding CodeArti, Mode=OneWay}"
                Header="Article" HeaderTextAlignment="Center" Width="90" UniqueName="article"/>
                            <telerik:GridViewDataColumn
                               TextAlignment="Left" IsReadOnly="True"
                               DataMemberBinding="{Binding Mode=OneWay, ElementName=textBox1, Path=Text}"
                Header="TEST" HeaderTextAlignment="Center" Width="*" />
     </telerik:RadGridView.Columns>
</telerik:RadGridView>

 
0
AMO
Top achievements
Rank 1
answered on 14 Mar 2013, 07:20 AM
thanx :)
0
Scott Waye
Top achievements
Rank 1
answered on 23 Jan 2015, 02:47 PM
This is poor.  IsVisible on GridViewColumn is a dependency property, therefore it should be bindable.  If a breakpoint is added to the binding in the XAML, then you can see that initially the datacontext is correct, but subsequently it gets set to something else and the binding evaluates to null which makes the column visible.  At the least you should be able to navigate to the IsVisible property in the object explorer and see a comment explaining that it cannot be used for binding.

In my case I have the grid in a user control which exposes a dependency property that that view model can bind to.  The workaround of John's with the loaded event did not work, but changing the binding to:

IsVisible="{Binding ShowShare, ElementName=root}"

where root is the name of the UserControl element in the XAML works.
0
Rob Ainscough
Top achievements
Rank 1
answered on 05 Mar 2015, 07:18 PM
I'm using Q1 2015 UI Silverlight Controls and the IsVisible binding to MVVM issue still remains? 

I've tried all the suggested work arounds viable for MVVM and none have worked.

Looks like Telerik have just stopped responding to this thread (which is 4 years long) even though it appears to be a need for many developers (myself included).

So is Telerik's official response "too difficult to implement"?

Cheers, Rob.


0
Rob Ainscough
Top achievements
Rank 1
answered on 06 Mar 2015, 01:05 AM
UPDATE: I did try Maya sample project (bindingtoisvisible.zip) ... it does work BUT it's really only practical for demonstration purposes.  

A production application would never instantiate the VM that way -- just not flexible ... I would expect (at least ours) production applications to setup the DataContext in a New instance of the UserControl passing whatever parameters are needed.

I was able to setup a checkbox that binds to IsVisible on a column but again that's user interaction which is not MVVM where I need to setup the IsVisible on the columns based on some parameter/state.

So at this point we've hit a rather significant show stopper unless this is implemented.  Being able to hide columns in a grid using MVVM is key for our requirements.

Does anyone have any suggestions of alternate vendors that might provide such functionality in their Grids?

Cheers, Rob.
0
Rob Ainscough
Top achievements
Rank 1
answered on 06 Mar 2015, 04:44 PM
FYI, this is the ONLY approach that has worked for me for MVVM.  Big thank you to Rodrigo.

A lot of code for something so so so very simple ... it's one of those 14 years ago it would take 3 seconds and one line of code to hide a column ... today it's add a helper class, 20-30 lines of code ... this is progress??  If it is, then the future of software development is going to be pretty bleak. 

Cheers, Rob.
0
meir
Top achievements
Rank 1
answered on 02 Nov 2017, 07:49 PM

Hi, I wanna bind a GridViewDataColumn IsVisible property, is there any way I can get that, Please...

Vlad, please don't just answer no, just tell me exactly how to get this done.

0
Vladimir Stoyanov
Telerik team
answered on 07 Nov 2017, 02:54 PM
Hello,

Can you check out the attached project where the Position column's IsVisible property in the nested grid is bound to a property in the Model? Please give this a try and let me know if that works for you. If you need further assistance, may I ask you to provide some more information about your scenario and perhaps a sample project.

I am looking forward to hearing from you.

Regards,
Vladimir Stoyanov
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Asked by
Eric Zeng
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Eric Zeng
Top achievements
Rank 1
Rodrigo Rodriguez
Top achievements
Rank 1
Kaka
Top achievements
Rank 1
Milan
Telerik team
Juan
Top achievements
Rank 1
Jaroslav Půbal
Top achievements
Rank 1
Maya
Telerik team
Jarred Froman
Top achievements
Rank 1
Sam
Top achievements
Rank 1
Alexey Oyun
Top achievements
Rank 1
kulashaker
Top achievements
Rank 1
Devon
Top achievements
Rank 1
Dave Clark
Top achievements
Rank 1
Geoff
Top achievements
Rank 1
Dave Swersky
Top achievements
Rank 1
Terry Foster
Top achievements
Rank 1
Pavel Pavlov
Telerik team
John
Top achievements
Rank 1
Brian
Top achievements
Rank 1
Iurii
Top achievements
Rank 1
Prakash
Top achievements
Rank 1
Paul McNamara
Top achievements
Rank 1
Matthias
Top achievements
Rank 1
Kelly
Top achievements
Rank 1
Tim
Top achievements
Rank 1
JJ Loubser
Top achievements
Rank 1
Juliana
Top achievements
Rank 1
guillekang
Top achievements
Rank 1
John
Top achievements
Rank 1
Bob
Top achievements
Rank 1
Chethan
Top achievements
Rank 1
Tingting
Top achievements
Rank 1
AMO
Top achievements
Rank 1
Scott Waye
Top achievements
Rank 1
Rob Ainscough
Top achievements
Rank 1
meir
Top achievements
Rank 1
Vladimir Stoyanov
Telerik team
Share this question
or