The top header of "DataGridView – Stacked Header" is not fixed in the column and scrolls.

Asked 2 years ago, Updated 2 years ago, 97 views

"DataGridView – Stacked Header" is used.
It was introduced on this site (codeproject.com).

It worked well without fixing the column, but it doesn't work properly when fixing the column.The top tier of the hierarchical column header scrolls even though it is fixed in the column.

If you know how to fix this, could you tell me?
Thank you for your cooperation.

private void Form1_Load (object sender, EventArgse)
{
    This.datatable=newDataTable();

    This.datatable.Columns.Add("a");
    This.datatable.Columns.Add("b");
    This.datatable.Columns.Add("c");
    This.datatable.Columns.Add("d");
    This.datatable.Columns.Add("e");
    This.datatable.Columns.Add("f");

    This.datatable.Rows.Add (new object[]{1,2,3,4,5,6});
    This.datatable.Rows.Add (new object[]{11, 22, 33, 44, 55, 66});

    for (inti=0; i<this.datatable.Columns.Count;i++)
    {
        string colName = this.datatable.Columns[i].ColumnName;

        DataGridViewColumn dataGridViewColumn=newDataGridViewTextBoxColumn();
        dataGridViewColumn.DataPropertyName=colName;

        string groupName;

        if(i<=2)
        {
            groupName = "first";
            dataGridViewColumn.Frozen=true;
        }
        else
        {
            groupName = "second";
            dataGridViewColumn.Frozen=false;
        }

        dataGridViewColumn.HeaderText=groupName+."+colName;

        This.dataGridView1.Columns.Add(dataGridViewColumn);
    }

    This.dataGridView1.DataSource=this.datatable;

    StackedHeaderDecorator objREnder=
        new StackedHeaderDecorator (this.dataGridView1);
}

Before scrolling:

Before Scroll

After scrolling:
The top column header is scrolling.

After scrolling

c# datagridview

2022-09-30 17:13

1 Answers

The StackedHeader library in the reference article itself does not seem to take into account the Frozen setting to fix the column display.

For example, if you configure the Frozen property true settings in the designer in the column that is initially displayed in the sample program Test.cs, only the bottom header is fixed and everything else scrolls.

You will probably need to add Frozen related information and configuration actions to the following areas for each library source:

Header.cs

  • Header Class Properties FrozenNo Related Information
  • Measure()

StackedHeaderDecorator.cs

  • RenderColumnHeaders()
  • Render()

StackedHeaderGenerator.cs

  • GenerateStackedHeader()


2022-09-30 17:13

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.