Reputation: 3539
I have a very tricky situation where I am binding data to telerik radgridview where everything works until I try and bind the visibility of one checkbox column based on the the check value of another of the columns. I have tried the following:
<telerik:RadGridView ShowGroupPanel="False" AutoGenerateColumns="False" ItemsSource="{Binding ParametersFilterConfigurations}">
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn IsFilterable="False" IsGroupable="False" IsSortable="False" DataMemberBinding="{Binding FilterElementName}" Header="Parameter Name" />
<telerik:GridViewCheckBoxColumn IsFilterable="False" IsGroupable="False" IsSortable="False" DataMemberBinding="{Binding CanView}" Header="Viewable"/>
<telerik:GridViewCheckBoxColumn IsVisible="{Binding CanView}" IsFilterable="False" IsGroupable="False" IsSortable="False" DataMemberBinding="{Binding CanFilterBy}" Header="Filterable" />
</telerik:RadGridView.Columns>
</telerik:RadGridView>
When I run this WPF attempts to locate the IsVisible="{Binding CanView" of the last column from the main datacontext and offcourse fails with the following:
System.Windows.Data Error: 40 : BindingExpression path error: 'CanView' property not found on 'object' ''MainWindow' (Name='')'. BindingExpression:Path=CanView; DataItem='MainWindow' (Name=''); target element is 'GridViewCheckBoxColumn' (HashCode=53813616); target property is 'IsVisible' (type 'Boolean')
How can I solve this? Please help.
Upvotes: 1
Views: 1173
Reputation: 102753
I suggest using a cell template for the "Filterable" column. Since the "CanView" property changes per row, there's no way you can bind another entire column's visibility to that. What you can do is always show the column, but show/hide a checkbox in that column as needed. Ie, something like this:
<telerik:GridViewColumn>
<telerik:GridViewColumn.CellTemplate Header="Filterable">
<DataTemplate>
<CheckBox Visibility="{Binding CanView,Converter={StaticResource BoolToVisConverter}"
IsChecked="{Binding CanFilterBy}"
/>
</DataTemplate>
</telerik:GridViewColumn.CellTemplate>
</telerik:GridViewColumn>
Upvotes: 1