0

I have some data in a grid that currently displays like this:

----------------------------------------------------------------
|InfoA  |InfoA |InfoB |InfoB |InfoC |InfoC |InfoD |InfoD |
----------------------------------------------------------------
|A1    |A2    |B1    |B2     |C1    |C2    |D1    |D2    |
----------------------------------------------------------------
|A3    |A4    |B3    |B4     |C3    |C4    |D3    |D4    |
----------------------------------------------------------------
|A5    |A6    |B5    |B6     |C5    |C6    |D5    |D6    |
----------------------------------------------------------------
|A7    |A8    |B7    |B8     |C7    |C8    |D7    |D8    |
----------------------------------------------------------------

I want to make it look like this:

----------------------------------------------------------------
|InfoA        |InfoB         |InfoC         |InfoD         |
----------------------------------------------------------------
|A1    |A2    |B1    |B2     |C1    |C2    |D1    |D2    |
----------------------------------------------------------------
|A3    |A4    |B3    |B4     |C3    |C4    |D3    |D4    |
----------------------------------------------------------------
|A5    |A6    |B5    |B6     |C5    |C6    |D5    |D6    |
----------------------------------------------------------------
|A7    |A8    |B7    |B8     |C7    |C8    |D7    |D8    |
----------------------------------------------------------------

Is there any way that I can merge these cells? I have tried in many ways also google but did not find any suitable way. If it is possible showing this data another way without using datagridview but the result is the way I have showed, that will also solve my problem. Thank in advance.

Oosutsuke
  • 79
  • 3
  • 12
  • 1
    A simple SO search for keywords [DataGridView Merge](http://stackoverflow.com/search?q=datagridview+merge) (optional: Cells, Header+Cell, et.al.) would have sufficed. (Small sampling... [1](http://stackoverflow.com/q/2063951/3773066), [2](http://stackoverflow.com/q/16774966/3773066), [3](http://stackoverflow.com/q/41891108/3773066), [4](http://stackoverflow.com/q/1366436/3773066)) – OhBeWise Feb 21 '17 at 13:41
  • Possible duplicate of [Merge cells in datagridview](http://stackoverflow.com/questions/2063951/merge-cells-in-datagridview) – OhBeWise Feb 21 '17 at 13:43
  • Thank OhBeWise, I've looked at it thoroughly but I don't understand the answer given similar here http://stackoverflow.com/questions/16774966/how-to-merge-datagridview-cell-in-winforms Other than that it's confusing. How to merge 2 rows :( – Oosutsuke Feb 21 '17 at 14:02
  • You are going to have to implement the `OnPaint` event to accomplish this. If you do not understand or find this too difficult, have you considered taking the header row completely out of the `DataGridView` then strategically placing headers above the `DataGridView` using either another `DataGridView` with one row or some other component? – JohnG Feb 21 '17 at 14:19
  • Because I want to manipulate the data within the datagridview for the header of the datagridview, I dont want to pull the header out of the datagridview. – Oosutsuke Feb 21 '17 at 14:55
  • Take the 3rd sampling I posted as a starting point, since I answered that question I'm most familiar with it. The idea is to handle the `DataGridView.Paint` event. In that event, you'll get the display rectangle of the first column, add the width of the next column, then fill & draw that rectangle and its text. (Follow this pattern for your 1st column, 3rd column, 5th column, etc.) Nevermind any code dealing with height - you don't need it in your example. The rest of the code in that example is to aid with triggering repaints after resizing occurs. – OhBeWise Feb 21 '17 at 18:40
  • Make your best attempt. If you still can't get it to work, edit your question to include your attempts, the problems you encountered, and anything you didn't understand. Reference the other question if needed. Then you have a unique question - no longer duplicate - and we can give additional help. – OhBeWise Feb 21 '17 at 18:43

0 Answers0