0

I want to merge cell in a header which I want to set on top of the column name in DataGridView and Header should be in center format. Just like, I had shown the sample in the image.

Sample

I tried some code from this link but it didn’t work for me.

Community
  • 1
  • 1
Ganesh
  • 7
  • 1
  • 8
  • You cannot really merge them, you need to paint headers yourself. – Reza Aghaei Jul 02 '18 at 08:03
  • But How ? @Reza Aghaei – Ganesh Jul 02 '18 at 08:06
  • What do you mean by "I tried some code from this below link but it didn’t work for me" ? Did you try some of the code? All of it? What was the result and how did it differ from what you want? – o_weisman Jul 02 '18 at 08:08
  • Take a look at [this post](https://stackoverflow.com/a/4086133/3110834) for example or [this one](http://csharpdotnet2012.blogspot.com/2012/02/v-behaviorurldefaultvmlo.html). – Reza Aghaei Jul 02 '18 at 08:09
  • Hello o_weisman, i want the header should be in center when i want to merge the 3 cells. – Ganesh Jul 02 '18 at 08:12
  • Check this https://stackoverflow.com/questions/41891108/merge-mulitple-row-headers-in-a-datagridview-with-c-sharp – Hitesh Anshani Jul 02 '18 at 10:50

1 Answers1

0

This code may help you..

        wBook = _excel.Workbooks.Add()
        wSheet = wBook.ActiveSheet()
        wSheet.Range(wSheet.Cells(vRow, vColNature), wSheet.Cells(vRow, vColMAX)).Merge()
            wSheet.Range(wSheet.Cells(vRow, vColNature), wSheet.Cells(vRow, vColMAX)).WrapText = True
            wSheet.Range(wSheet.Cells(vRow, vColNature), wSheet.Cells(vRow, vColMAX)).Font.Bold = True
            wSheet.Range(wSheet.Cells(vRow, vColNature), wSheet.Cells(vRow, vColMAX)).Borders.LineStyle = 1

            wSheet.Range(wSheet.Cells(vRow, vColNature), wSheet.Cells(vRow, vColMAX)).HorizontalAlignment = Excel.Constants.xlCenter