question

WillingMost7-4552 avatar image
0 Votes"
WillingMost7-4552 asked SimpleSamples answered

Split cells in datagridview C#

Hi .. I've searched the whole internet but couldn't find anything so I hope you can help me (please).

I want to divide a cell into two in a DataGridView, for example:

 -------------------------------
 |    Sunday      |     Monday   |
 -------------------------------
 |   B     |  A       |   C    |   D     |
 -------------------------------
 | info   | info    | info  |   info |
 -------------------------------

Couldn't manage to split it like that.

P.S: I would also like to know how to color a text in a cell with two different colors.

Thanks in advance!

dotnet-csharp
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

karenpayneoregon avatar image
0 Votes"
karenpayneoregon answered

For splitting cells you will need to find a custom DataGridView. In regards to different colors in the same cell, this is not supported in a standard DataGridView, this means custom painting as per the following or custom column/cell as per this page.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

SimpleSamples avatar image
0 Votes"
SimpleSamples answered

I am not sure what you need to do; what I see for the formatting in your example is probably not accurate. I assume that you want a DataGridView with 4 columns except at the top you want a header with 2 columns, each of the two columns containing a header for two of the other columns.

You could create a DataGridView with 2 columns and 2 rows. The first row would be the headers. Each of the second rows could contain another DataGridView that is 2 columns.

Another possibility would be to create a 2-column DataGridView with 1 row that is above the other DataGridView and otherwise separate. You would need to position the 2-column DataGridView to get everything to look proper.

It might be difficult to keep the sizes coordinated properly but otherwise it should be easier to implement one of those than to implement any of the other alternatives.

I am not sure what color a text in a cell with two different colors means. Do you mean different colors within a cell or do you mean different colors for cells? If the latter then see the DataGridViewCellStyle.ForeColor Property. Normally it works better if there is only one question in a question in these forums so if you are asking how to use different colors within a single cell then it would be better to create a different question for that.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.