0

我有一个包含 DataGridView 的面板。我需要面板和(反过来)DataGridView 来填充表单的顶部 1/2。当 DGV 试图隐藏列标题时,问题就出现了。

控制板:

{
    public DgvAccounts dgvAccounts;
    public SidePanel sidePanel;
    public TopPanel()
    {
            this.dgvAccounts = new DgvAccounts();
            this.sidePanel = new SidePanel();

            this.SuspendLayout();
            this.AutoScroll = true;
            this.Controls.Add((Control)this.dgvAccounts);
            this.Controls.Add((Control)this.sidePanel);
            this.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
            this.Dock = DockStyle.Fill;
            this.Location = new Point(0, 24);
            this.Name = "TopPanel";
            this.AutoSize = true;
            this.AutoSizeMode = AutoSizeMode.GrowOnly;
            this.TabIndex = 21;
            this.ResumeLayout(false);
            this.PerformLayout();
    }
}

Dgv帐户:

public class DgvAccounts : DataGridView
{
    public DgvAccounts()
    {
            DataGridViewCellStyle dgvcSyle = new DataGridViewCellStyle();
            dgvcSyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dgvcSyle.BackColor = SystemColors.Control;
            dgvcSyle.Font = new Font("Segoe UI", 8.25f, FontStyle.Regular, GraphicsUnit.Point, (byte)0);
            dgvcSyle.ForeColor = SystemColors.WindowText;
            dgvcSyle.SelectionBackColor = SystemColors.Highlight;
            dgvcSyle.SelectionForeColor = SystemColors.HighlightText;
            dgvcSyle.WrapMode = DataGridViewTriState.True;


            DataGridViewCellStyle dgvcSyleMid = new DataGridViewCellStyle();
            dgvcSyleMid.Alignment = DataGridViewContentAlignment.MiddleCenter;

            ((ISupportInitialize)this).BeginInit();
            this.AllowUserToAddRows = false;
            this.AllowUserToDeleteRows = false;
            this.AllowUserToOrderColumns = true;
            this.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
            this.ColumnHeadersDefaultCellStyle = dgvcSyle;
            this.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.ColumnHeadersVisible = true;
            this.Columns.AddRange((DataGridViewColumn)this.colCheckBox, (DataGridViewColumn)this.Account,...);
            this.Location = new Point(5, 3);
            this.Name = "dgvAccounts";
            this.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            this.AutoSize = true;
            this.SetAutoSizeMode(AutoSizeMode.GrowOnly);
            this.TabIndex = 1;
            this.AllowUserToResizeRows = false;
            this.RowHeadersVisible = false;
            ((ISupportInitialize)this).EndInit();


            this.colCheckBox.DataPropertyName = "colCheckBox";
            this.colCheckBox.HeaderText = "Select";
            this.colCheckBox.Name = "colCheckBox";
            this.colCheckBox.Resizable = DataGridViewTriState.False;
            this.colCheckBox.Width = 50;

            this.Account.DataPropertyName = "Account";
            this.Account.DefaultCellStyle = dgvcSyleMid;
            this.Account.HeaderText = "Account";
            this.Account.Name = "Account";
            this.Account.ReadOnly = true;
    }
}

如何让 Panel 和 DgvAccounts 拉伸整个表单的整个宽度,但仍然让 DgvAccounts 显示 Headers 字段?(这必须允许 SidePanel 在 SidePanel 可见时调整 DgvAccounts 的大小。)

没有面板的视图是 DockStyle.Fill: 在此处输入图像描述

面板为 DockStyle.Fill 的视图:在此处输入图像描述

4

0 回答 0