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.
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.
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.
Here is the Complete Source Code for the application.
- How to Save to and Retrieve Image from Database in C# Windows Application.
- What is WCF Contract?.
- An Introduction to WCF.
Hope you understand this post about How to Merge DataGridView Cells in C# Windows Application. I will appreciate your feedback, comments and suggestions.