The text of this article is not in this database — only its details are. The old site it was published on is gone, but the Internet Archive kept a copy: Hide/Un-Hide Columns using Context Menu in DataGrid in WPF
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment
It is the same account you read, post and publish with — and you will come straight back to this page.

Guest UserPosted Mar 15, 2016, 3:22 AM
Have you tried to collapse/show columns instead of unload and load items of DataGrid? I think it's more efficient. Like this: Private Sub menuItem_Checked(sender As Object, e As RoutedEventArgs)Dim item As MenuItem = TryCast(sender, MenuItem)SetItemVisibility(item, Visibility.Visible)End Sub Private Sub SetItemVisibility(ByRef item As MenuItem, ByVal visibilidad As Visibility) If item IsNot Nothing Then For Each columna As DataGridColumn In _dataGrid.Columns If columna.Header.ToString.Equals(item.Header.ToString) Then columna.Visibility = visibilidad Exit For End If Next End If End Sub
abhi sharmaPosted Apr 15, 2013, 10:42 AM
Hello Diptimaya, This was a wonderful article and helped me a lot!!I think there is some logical error in menuItem_checked Event.As the MenuItem item variable is not used in the event and hence isChecked is always set to true. Hope u would notice!!!!! Again thanks
Jeff MainPosted Nov 16, 2010, 9:52 PM
Do you have a net4 VS2010 update to this topic? I can't seem to convert this, as I get errors with the DataGridColumnHeaders under net4.0 using Microsoft.Windows.Controls.Primitives. It compiles fine under 3.5, but not 4.0. What is the equivalent Net4 code? Thanks, Jeff
Vinod DPosted May 13, 2010, 7:18 AM
how can we make expand/collapsible in datagrid with child rows. can it be possible to add image along with data in one cell.