The question I have is, how can I combine cells in a DataGridView?
In my VB.NET project I have a DataGridView that displays information from a table in my MySQL database as follows:
And what I want is to combine the cells of the first column so that it looks something like this:
How do I do it?
The tables in the images are made in Excel just to give an example, it should be clarified that I only show 2 services but in reality there are 30 services.
The DataGridView does not provide this functionality.
In CodeProject if you can find an implementation of a column type for DataGridView that allows to do it:
DataGridVewTextBoxCell with Span Behavior
It basically creates a column type DataGridViewTextBoxColumnEx whose cells are of type DataGridViewTextBoxCellEx. These cells allow you to combine cells through their RowSpan and ColSpan properties.
An example of use:
The result:
To use it:
You could choose an option like being
How to Merge DataGridView Cell in Winforms
in the event
CellPainting
of the DataGridViewthere it validates if the value of the column is equal to that of the previous cell, if it is, it eliminates the line of the cells using
There is also another more complex way that uses GDI
MERGING CELLS IN DATAGRIDVIEW
This is the perfect solution to my problem, I share it for everyone to have.
The following instruction is placed in the Load event of the Form :
In the CellPainting event of the DataGridView we place the following:
In the CellFormatting event of the DataGridView we place the following:
And additionally we need to create a function: