Share via

C# Winform: How to develop merge column with Datagridview.

T.Zacks 3,996 Reputation points
Feb 22, 2023, 1:38 PM

I am looking for assitance that how to merge few specific columns with Datagridview. i am attaching a picture.

User's image

in the picture row which has Eric World that is data row from where data will be there in grid.

please provide a sample code to design a grid with merge columns with datagridview.

Thanks

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,181 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Minxin Yu 12,351 Reputation points Microsoft Vendor
    Feb 24, 2023, 8:36 AM

    Hi,

    DataGridView is difficult to achieve what you want.
    There are some examples of using custom GridView on Github for your reference.

    https://github.com/wsn931203/RowMergeView
    User's image

    Form1_Load:  
                this.rowMergeView1.Columns.Add("1", "Analyst");
                this.rowMergeView1.Columns.Add("2", "Date");
                this.rowMergeView1.Columns.Add("3", "Current");
                this.rowMergeView1.Columns.Add("4", "Previous");
                this.rowMergeView1.Columns.Add("5", "Current");
                this.rowMergeView1.Columns.Add("6", "Previous");
                this.rowMergeView1.Columns.Add("7", "Future");
                this.rowMergeView1.Rows.Add("1", "2", "3", "4", "5", "6", "7");
                this.rowMergeView1.ColumnHeadersHeight = 40;
                this.rowMergeView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
                
                this.rowMergeView1.AddSpanHeader(2, 2, "Price Target");
                this.rowMergeView1.AddSpanHeader(4, 3, "Rating");
    
                for (int i = 0; i < this.rowMergeView1.Columns.Count; i++)
                {
                    this.rowMergeView1.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
                }
    
    

    Best regards,

    Minxin Yu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.