Hide list column wpf

how to make a column invisible from wpf list? (one way is to set the width property to the minimum length, but this is not the correct solution) can anyone help me?

+8


source to share


4 answers


There is a fairly simple explanation of one way to do this here .

Find and remove the column:

var temp = myGridView.Columns[0];
myGridView.Columns.RemoveAt(0);

      



Insert the column back into the view:

myGridView.Columns.Add(temp );
temp.Width = 0;
temp.Width = Double.NaN;

      

Remove it from the Column Collection when you want to hide it and re-insert the column when you want to show it again.

+8


source


To hide the title of the ListView, you can change the Visibility property of the ColumnHeaderContainer by overriding the style locally.

<ListView>
<ListView.View>
    <GridView>
        <GridView.ColumnHeaderContainerStyle>
           <Style>
               <Setter Property="FrameworkElement.Visibility" Value="Collapsed"/>
           </Style>
        </GridView.ColumnHeaderContainerStyle>
        <GridView.Columns>
            ...
        </GridView.Columns>
    </GridView>
</ListView.View>

      



+1


source


I hope this helps someone:

The best way I have found is to do these two things:
1. Set the column width to 0 (this can also be done in the GridViewColumnHeader) - change it in the code if you want to show the column again.
2. Set the Visibility of the GridViewColumnHeader to Hidden - set it in code if you want to show the column again, or you can even use binding.

The second point above helps to make the column non-extensible by the user.

0


source


To hide a column, you can set the column width to zero and disable the header, like this:

Set the GridViewColumn Width and set the GridViewColumnHeader IsEnabled to False.

Example:

<GridViewColumn Width="{Binding ColumnWidth, Mode=OneWay}">
<GridViewColumnHeader Content="NΒΊ Item" IsEnabled="False" />

      

0


source







All Articles