CRUD Operation In DataGrid In WPF


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. J

Crating WPF Application Project

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

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

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

We would change the table names as follows:

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

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:

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.

Create and Update Operation

The following code describes the Create and Delete Operation.

Delete Operation

The following code represents the Delete Operation.

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. J

Hope this article helps.

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) Edit Row Details In Context Menu In DataGrid In WPF

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

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

11) ComboBox In DataGrid In WPF

12) DatePicker In DataGrid In WPF

About these ads