0

我经常遇到这个问题,在使用datagridview时,如果我需要使用水平滚动,它不会到表单的末尾。最后一列然后呈现为不可访问。我通常可以通过扩展 dgv 的大小或启动表单最大化来作弊,但是如果垂直滚动按预期工作(一直到数据集中的最后一条记录),为什么水平滚动不呢?

private void InitializeMemberGrid()
    {
        // Set grid properties
        this.grdMembers.AutoGenerateColumns = false;
        this.grdMembers.RowHeadersVisible = true;
        this.grdMembers.Columns.Clear();
        mPicWaiting = PartD.Windows.Common.Utility.AddWaitingImage(this.grdMembers);
        mPicWaiting.Visible = false;

        // Member ID Column
        var colMemberID = new DataGridViewTextBoxColumn();
        colMemberID.Name = "MemberID";
        colMemberID.HeaderText = "Member ID";
        colMemberID.DataPropertyName = "ID";
        this.grdMembers.Columns.Add(colMemberID);

        //// Contract ID Column
        var colContractID = new DataGridViewTextBoxColumn();
        colContractID.Name = "ContractID";
        colContractID.HeaderText = "Contract ID";
        colContractID.DataPropertyName = "ContractID";
        this.grdMembers.Columns.Add(colContractID);

        // SSN Column
        var colSSN = new DataGridViewTextBoxColumn();
        colSSN.Name = "SSN";
        colSSN.HeaderText = "SSN";
        colSSN.DataPropertyName = "SSN";
        this.grdMembers.Columns.Add(colSSN);

        // HICN Column
        var colHICN = new DataGridViewTextBoxColumn();
        colHICN.Name = "HICN";
        colHICN.HeaderText = "HICN";
        colHICN.DataPropertyName = "HICN";
        this.grdMembers.Columns.Add(colHICN);

        // Name Column
        var colName = new DataGridViewTextBoxColumn();
        colName.Name = "Name";
        colName.HeaderText = "Name";
        colName.DataPropertyName = "LastNameFirstName";
        colName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
        this.grdMembers.Columns.Add(colName);

        // DOB Column
        var colDOB = new DataGridViewTextBoxColumn();
        colDOB.Name = "DOB";
        colDOB.HeaderText = "DOB";
        colDOB.DataPropertyName = "DateOfBirth";
        colDOB.DefaultCellStyle.Format = "MM/dd/yyyy";
        this.grdMembers.Columns.Add(colDOB);

        // Retirement Date Column
        var colRetireDate = new DataGridViewTextBoxColumn();
        colRetireDate.Name = "RetireDate";
        colRetireDate.HeaderText = "Retirement";
        colRetireDate.DataPropertyName = "RetireDate";
        this.grdMembers.Columns.Add(colRetireDate);

        // RelCode Column
        var colRelCode = new DataGridViewTextBoxColumn();
        colRelCode.Name = "RelCode";
        colRelCode.HeaderText = "Rel";
        colRelCode.DataPropertyName = "RelCode";
        this.grdMembers.Columns.Add(colRelCode);

        // Resend Column
        var colResend = new DataGridViewTextBoxColumn();
        colResend.Name = "Resend";
        colResend.HeaderText = "Resend";
        colResend.DataPropertyName = "Resend";
        this.grdMembers.Columns.Add(colResend);

        // Sent Column
        var colSent = new DataGridViewTextBoxColumn();
        colSent.Name = "Sent";
        colSent.HeaderText = "Sent";
        colSent.DataPropertyName = "SubmissionCount";
        this.grdMembers.Columns.Add(colSent);

        // Status Column
        var colStatus = new DataGridViewTextBoxColumn();
        colStatus.Name = "Status";
        colStatus.HeaderText = "Status";
        colStatus.DataPropertyName = "Status";
        this.grdMembers.Columns.Add(colStatus);
    }
4

2 回答 2

0

您可能已经设置了控件的宽度,DataGridView而不是将控件停靠在表单中。

确保控件在设计器中看起来正确,然后将其锚定在右侧。如果调整表格大小,这将阻止结束列被切断。更好的是,添加一个面板以嵌入您的控件并相应地停靠它。

我希望这有帮助。

于 2012-04-05T15:20:44.727 回答
0

将最后一列的“AutoSizeMode”属性设置为“AllCells”为我修复了它:

column.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
于 2020-10-16T20:27:29.690 回答