Hide &Un-Hide DataGrid Column(s) In WPF


In this article we will see how we can hide or unhide the columns in a DataGrid.

Crating WPF Application Project

Fire up Visual Studio 2008 and Create a WPF Application and name the project as HideUnhideDGInWPF.

Here is the thing; we will have a DataGrid which will columns Auto Generated. We will have a Wrap Panel that will have the Check Boxes.

So here we go, add a class to generate sample data.

And create sample data and bind it to the DataGrid.

Now in the AutoGeneratedColumns event handler add the following code to generate the CheckBoxes.

Now we will work on the Hiding part for the Columns.

The following code is for un hiding the columns when uncheked.

That’s it, we have actually done it. Run the application.

And when Checked or Unchecked, it will work. J

Hope this article helps. J

Related Posts:

1) Making Timeline Control for DataGrid In WPF

2) Custom Gridline Color of Datagrid In WPF

3) Custom Row and Header Height of Datagrid In WPF

4) Rounded Corner Datagrid In WPF

5) Tooltip In DataGrid In WPF

6) Grouping In Datagrid In WPF

7) Cell Alignment In DataGrid In WPF

8) Edit Row Details In Context Menu In DataGrid In WPF

9) Hide/Un-Hide Columns Using Context Menu In DataGrid In WPF

10) ComboBox In DataGrid In WPF

11) DatePicker In DataGrid In WPF

12) CRUD Operation In DataGrid In WPF