0

I have a requirement to display data in the following format. I am trying to find a way to merge cells or provide colspan for the cells to achieve the functionality

DataGridView final view

Found couple of articles which provides some good idea on how to achieve it. I have atleast 10 rows and 24 columns per row so performance is also a factor

https://www.codeproject.com/Articles/34037/DataGridVewTextBoxCell-with-Span-Behaviour

http://forums.codeguru.com/showthread.php?415930-DataGridView-Merging-Cells

Let me know is there any other way to implement it or should I go with WPF grid in windows forms. Any thoughts on how to implement it?

Thanks for your time

Vinod
  • 343
  • 1
  • 4
  • 14
  • Although I like the first article you've linked, from my experience this is typically done more akin to your second link. For your reading, a couple of posts I've answered on merging headers: ([1](https://stackoverflow.com/a/35323076/3773066), [2](https://stackoverflow.com/a/41903334/3773066)) And a well-accepted SO suggestion: [How to Merge DataGridView Cell in Winforms](https://stackoverflow.com/q/16774966/3773066) – OhBeWise Dec 22 '17 at 16:55
  • I was actually looking at the link you suggested (https://stackoverflow.com/questions/16774966/how-to-merge-datagridview-cell-in-winforms) Only problem with that is I can't make the contents aligned center it will always be on the one cell). Second link in my post achieves the center alignment but the cells doesn't look like selected on click. – Vinod Dec 22 '17 at 17:15
  • Merged cells must be painted accordingly. There is no need to worry about performance. Only problem is how and where you want to save formatting data. – DotNet Developer Dec 22 '17 at 17:20
  • @Bahrom Is there any example or some guidelines on how do I make the merged cells select and deselect on click? – Vinod Dec 22 '17 at 18:46

1 Answers1

1

Standard DataGridView control, for example, does not support rich formatting (like Excel sheet). Only minimum - most required ones. All those solutions proposed in those posts given by you are trying to handle paint event and do some tricky painting, nothing more.

On the other hand, you should consider other alternatives too. If your data will be displayed for reading only then I recommend you to generate html document and display it with WebBrowser control. Html supports much more formatting, including merging cells.

DotNet Developer
  • 2,973
  • 1
  • 15
  • 24