Hide And Un-Hide DataGrid Columns In WPF

No.of Views867
Bookmarked0 times
Downloads 
Votes0
By  dpatra   On  05 May 2010 08:05:19
Tag : WPF , Grid Controls
In this article we will see how we can hide or unhide the columns in a DataGrid.
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

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.
 

Image Loading


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.
 

Image Loading

And create sample data and bind it to the DataGrid.

 

Image Loading

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

 

Image Loading

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

 

Image Loading

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

 

Image Loading

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

 

Image Loading

And when Checked or Unchecked, it will work.

 

Image Loading

Hope this article helps.

Sample Project Code

Download source files -529 kb

 
Sign Up to vote for this article
 
About Author
 
dpatra
Occupation-Not Provided
Company-Not Provided
Member Type-Expert
Location-Not Provided
Joined date-13 Jul 2009
Home Page-Not Provided
Blog Page-Not Provided
 
 
Other popularSectionarticles
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top