Introduction

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

Creating WPF Application Project

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

1.gif

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.

2.gif

And create sample data and bind it to the DataGrid.

3.gif

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

4.gif

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

5.gif

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

6.gif

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

7.gif

And when Checked or Unchecked, it will work.

8.gif

Hope this article helps.