Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
How to change visibility of column dynamically in xamdatagrid


<CheckBox IsEnabled="{Binding ShowGuideWeight}"></CheckBox>

<infragistic:XamDataGrid Grid.Row="1" DataSource="{Bindng LogList }" PreviewKeyDown="DataGrid_PreviewKeyDown" Name="InputGlobalWellsDataGrid"
                                            <infragistic:FieldLayoutSettings AutoGenerateFields="False" 
                                            AllowDelete="False" SelectionTypeRecord="Single"/>
                                            <Style x:Key="{x:Type infragistic:DataRecordCellArea}" TargetType="{x:Type infragistic:DataRecordCellArea}">
                                                    <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Record.DataItem.IsOk, UpdateSourceTrigger=PropertyChanged}"  Value="false">
                                                        <Setter Property="BorderBrush" Value="#FFFFDC00"/>
                                                    <infragistic:Field Name="Name" Label="Name"></infragistic:Field>
                                                    <infragistic:Field Name="GuideWeight" Label="Guide weight">
                                                            <Style TargetType="{x:Type igEdit:XamNumericEditor}">
                                                                <Setter Property="Visibility" Value="{Binding DataContext.ShowGuideWeight, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}, Converter ={StaticResource boltoVis}}"/>


I  manage tho change the visibility of the cell but, how can I collapse the whole column (I also want to hide the header,) The visilibty of that clown show depend on the click of the checkbox

No Data
  • 160
    Verified Answer
    Offline posted

    My suggestion for achieving a conditional column visibility is to handle Checked/Unchecked events of the CheckBox. There you can set the visibility of the field you choose. For example:
     private void CheckBox_Checked(object sender, RoutedEventArgs e)
                  this.grid.FieldLayouts[0].Fields["Height"].Visibility = Visibility.Collapsed;

    In this case visible or hidden would be not only cells but the header as well.

    Another approach (if you do not watt to use this events and instead use binding like the code-snippet you provided) is to add overriding of the LabelPresenter style and to bind its Visibility property just like the cell's visibility. This will hide or show the column header.
    I have attached a sample application that demonstrate these approaches.
    If you require any further assistance on the matter, please let me know.
    Teodosia Hristodorova
    Associate Software Developer
No Data