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
315
How to change visibility of column dynamically in xamdatagrid
posted

 

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

<infragistic:XamDataGrid Grid.Row="1" DataSource="{Bindng LogList }" PreviewKeyDown="DataGrid_PreviewKeyDown" Name="InputGlobalWellsDataGrid"
                            GroupByAreaLocation="None">
 <infragistic:XamDataGrid.FieldLayoutSettings>
                                            <infragistic:FieldLayoutSettings AutoGenerateFields="False" 
                                            AutoFitMode="Always" 
                                            AddNewRecordLocation="OnTopFixed"
                                            AllowAddNew="True"
                                            SupportDataErrorInfo="RecordsAndCells"
                                            DataErrorDisplayMode="Highlight"
                                            AllowDelete="False" SelectionTypeRecord="Single"/>
                                        </infragistic:XamDataGrid.FieldLayoutSettings>
                                        <infragistic:XamDataGrid.Resources>
                                            <Style x:Key="{x:Type infragistic:DataRecordCellArea}" TargetType="{x:Type infragistic:DataRecordCellArea}">
                                                <Style.Triggers>
                                                    <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Record.DataItem.IsOk, UpdateSourceTrigger=PropertyChanged}"  Value="false">
                                                        <Setter Property="BorderBrush" Value="#FFFFDC00"/>
                                                    </DataTrigger>
                                                </Style.Triggers>
                                            </Style>
                                        </infragistic:XamDataGrid.Resources>
                                        <infragistic:XamDataGrid.FieldLayouts>
                                            <infragistic:FieldLayout>
                                                <infragistic:FieldLayout.Fields>
                                                    <infragistic:Field Name="Name" Label="Name"></infragistic:Field>
                                                    <infragistic:Field Name="GuideWeight" Label="Guide weight">
                                                        <infragistic:Field.EditorStyle>
                                                            <Style TargetType="{x:Type igEdit:XamNumericEditor}">
                                                                <Setter Property="Visibility" Value="{Binding DataContext.ShowGuideWeight, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}, Converter ={StaticResource boltoVis}}"/>
                                                            </Style>
                                                        </infragistic:Field.EditorStyle>
                                                    </infragistic:Field>

                                                </infragistic:FieldLayout.Fields>
                                            </infragistic:FieldLayout>
                                        </infragistic:XamDataGrid.FieldLayouts>
                                    </infragistic:XamDataGrid>

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

  • 160
    Verified Answer
    Offline posted
    Hello,

    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.
    Sincerely,
    Teodosia Hristodorova
    Associate Software Developer