Edit Row Details In Context Menu In DataGrid In WPF

No.of Views1877
Bookmarked1 times
Downloads 
Votes0
By  dpatra   On  26 Apr 2010 10:04:18
Tag : WPF , Grid Controls
In this article we will try something else; we will edit the Selected Row Details in ContextMenu.
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 my previous article on “Hide/Un-Hide Columns Using Context menu In DataGrid In WPF”, we saw how we can display ContextMenu on Column Headers. In this article we will try something else; we will edit the Selected Row Details in ContextMenu.

Creating WPF Application Project

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

 

Image Loading

We need to load sample data into the DataGrid.

 

Image Loading

Create a list of data based on above entity and bind it to the DataGrid in the Constructor of the Window.

 

Image Loading

Now run the application to see the DataGrid with full of Data.

 

Image Loading

Here’s is the steps we will follow. First we need to handle the SelectionChanged event for DataGrid to generate the ContextMenu.
Add the Handler in the Constructor.
 

 

Image Loading

Then in the event add the following code to generate the ContextMenu.

 

Image Loading

Now in the Button Click event we will save data. Remember in this sample I am saving the List, in real time you can change based on your datasource.
Add the following code into Button Click event that we have just added in the above event.
 

 

Image Loading

Now we have to handle the MouseRightButtonUp of DataGrid to display the ContextMenu.

 

Image Loading

That’s it we are done. Now run the application.

 

Image Loading

Now Change some detail and click on Save Button.

 

Image Loading

Sample Project Source

Download source files -21 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
By:BrijeshDate Of Posted:3/9/2011 6:13:26 AM
best article
This article is superb.... this help alot to solve my problem related to datagrid doubleclick event
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