SIGN UP MEMBER LOGIN:    
ARTICLE

Edit Row Details in Context Menu in DataGrid in WPF

Posted by Diptimaya Patra Articles | WPF with C# February 22, 2010
In this article we will see how to edit the selected row details in ContextMenu.
Reader Level:
 

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.

1.gif
 
We need to load sample data into the DataGrid.

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

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

4.gif
 
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.

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

6.gif
 
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.

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

8.gif
 
That's it we are done. Now run the application.

9.gif
 
Now Change some detail and click on Save Button.

10.gif
 
See the saved data.

11.gif
 
Hope this article helps.

Login to add your contents and source code to this article
Article Extensions
Contents added by javaxiao king on Feb 28, 2011
share this article :
post comment
 

I very Interesting with all post document and i will try learn English very good to talk to you. My nick is daisy88vo
Thanks 

Posted by Vo Thao Aug 27, 2010
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor