Click here to Skip to main content
15,672,129 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I'm populating a DataGrid inside my WPF window like this
'dgFollowup.DataContext = ds.Tables[0]' .
Can any one tell me how to Hide or make a column invisible inside the DataGrid.

Thanks & Regards,
Updated 4-May-11 0:39am

dataGrid2.Columns[0].Visibility = Visibility.Hidden;
Share this answer
I assume that you are using automatic column population to populate your grid. If you want to hide a column, then you can't really do this - you need to explicitly set the column information manually. To do this, use something like this:
<dg:DataGrid x:Name="dgFollowUp" AutoGenerateColumns="False">
    <dg:DataGridTextColumn Binding="{Binding Column1}" Header="Column 1" />
    <dg:DataGridTextColumn Binding="{Binding Column2}" Header="Column 1" />
</dg:DataGrid AutoGenerateColumns="False">
Share this answer
Ramana Bellary 4-May-11 23:30pm    
Thank you Pete O'Hanlon.
Pete O'Hanlon 5-May-11 2:02am    
You are welcome. I am glad to help.
Additionally, While
AutoGenerateColumns="True" you can handle the WPF datagrid event: DataGrid1_AutoGeneratingColumn(....)
you will find e.Column.Header, compare the columns which all you want to hide, then simply do as e.Column.Visibility = visibility.Hidden
Share this answer
Member 14677029 11-Aug-21 16:09pm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900