ARTICLE

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

Posted by Diptimaya Patra Articles | WPF February 19, 2010
In this article we will see how we can hide or unhide the columns in a DataGrid.
Reader Level:
Download Files:
 

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.

Login to add your contents and source code to this article
post comment
     
COMMENT USING
PREMIUM SPONSORS
DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and add new content to existing PDF documents from within your applications.
Get Career Advice from Experts
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.