Edit Row Details In Context Menu In DataGrid In WPF


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.

Crating WPF Application Project

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

We need to load sample data into the DataGrid.

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

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

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.

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

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.

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

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

Now Change some detail and click on Save Button.

See the saved data.

Hope this article helps. J

Related Posts:

1) Making Timeline Control for DataGrid In WPF

2) Custom Gridline Color of Datagrid In WPF

3) Custom Row and Header Height of Datagrid In WPF

4) Rounded Corner Datagrid In WPF

5) Tooltip In DataGrid In WPF

6) Grouping In Datagrid In WPF

7) Cell Alignment In DataGrid In WPF

8) Hide/Un-Hide Columns Using Context Menu In DataGrid In WPF

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

10) ComboBox In DataGrid In WPF

11) DatePicker In DataGrid In WPF

12) CRUD Operation In DataGrid In WPF