CRUD Operation In DataGrid In WPF

No.of Views3503
Bookmarked0 times
Downloads 
Votes0
By  dpatra   On  21 Apr 2010 11:04:37
Tag : WPF , How to
I have been getting requests to write article on DataGrid CRUD operation without using any other control. So this article is for all the requestors.
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


I have been getting requests to write article on DataGrid CRUD operation without using any other control. So this article is for all the requestors. I have used only DataGrid for CRUD operation

Creating WPF Application Project

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

Image Loading

We would use Linq to SQL as our ORM. So add like below figure. 

Image Loading

Now after adding, open the Server Explorer and add the required table, in our case EMP_BASIC_INFO. 

Image Loading

We would change the table names as follows: 

Image Loading

Now in Blend I have designed the WPF Application like the below figure.

 

Image Loading
The design displayed above contains a DataGrid for CRUD Operations and a TextBlock to display status messages. It’s below the DataGrid.
The following XAML code is for your reference:
 
Image Loading
 We will perform the operation in below order:
1.    Read
2.    Create and Update
3.    Delete
 

Read Operation

 The following code describes the read operation.

Image Loading

Create and Update Operation

The following code describes the Create and Delete Operation.

 

Image Loading

Delete Operation

The following code represents the Delete Operation.

Image Loading

Now run the application and all the CRUD operations are successfully used.Note: Code is not written for multi select delete. It can be done the same way single select, try doing it.
Hope this article helps.
 

Sample Project Source

Download source files -545 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