Click here to Skip to main content
15,902,492 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi,
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,
Ramana
Posted
Updated 4-May-11 0:39am
v2

dataGrid2.Columns[0].Visibility = Visibility.Hidden;
 
Share this answer
 
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
 
Comments
Member 14677029 11-Aug-21 16:09pm    
https://docs.microsoft.com/en-us/dotnet/api/system.windows.controls.datagrid.autogeneratingcolumn?view=net-5.0
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:
XML
<dg:DataGrid x:Name="dgFollowUp" AutoGenerateColumns="False">
  <dg:DataGrid.Columns>
    <dg:DataGridTextColumn Binding="{Binding Column1}" Header="Column 1" />
    <dg:DataGridTextColumn Binding="{Binding Column2}" Header="Column 1" />
  </dg:DataGrid.Columns>
</dg:DataGrid AutoGenerateColumns="False">
 
Share this answer
 
Comments
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.

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