我经常遇到这个问题,在使用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);
}