Home > Windows Application > How to Merge DataGridView Cells in C# Windows Application

How to Merge DataGridView Cells in C# Windows Application

In this tutorial, we are going to see how we can merge DataGridView Cells in C# Windows Application. DataGridView is always an important control in Windows Application for showing Table Data. In some cases, we need to merge two or more cells in DataGridView for showing data as a Report. Here we are going to develop the same example in C# Windows Application.

After Completing this tutorial you will be able to understand:

  • How to Merge DataGridView Cells in C# Windows Application.

How to Merge DataGridView Cells in C# Windows Application:

Step 1: Open Visual Studio and Create a C# Windows Application called MergeDataGrdViewCellsDemo.

Merge DataGridView Cells

Step 2: Drag a DataGridView on the Windows Form.

Step 3: Set the Name property of the DataGridView to dgvData.

Step 4: Set the Dock Property of DataGridView to Fill.

Step 5: Set the AutoSizeColumnMode of DataGridView to Fill.

Your Windows Form should look like this.

Merge DataGridView Cells

Step 6: The Next step is to prepare DataTable for DataGridView. Open Code Behind File and write the following method.

Step 7: Now we need to set Data to the DataTable. Write the following method in Code Behind File.

Step 8: Write the following code on Form Load event.

Step 9: Create a method to check the value of cells are equal or not.

Step 10: Write the following code on DataGridView Cell Painting Event.

Step 11: Now finally write the following code on DataGridView Cell Formatting Event.

Now run the application and look over the output window.

Merge DataGridView Cells

Here is the Complete Source Code for the application.

View More:

Conclusion:

Hope you understand this post about How to Merge DataGridView Cells in C# Windows Application. I will appreciate your feedback, comments and suggestions.

Thank You.

5 Comments

  1. Its like you read my mind! You seem to understand so much approximately this, such as you wrote the guide in it or something. I think that you just could do with a few percent to drive the message home a little bit, but instead of that, that is excellent blog. A great read. I’ll certainly be back.

  2. Pingback: Google

Leave a Reply

Your email address will not be published.