我经常遇到这个问题,当使用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);
}
答案 0 :(得分:0)
您可能已设置DataGridView
的宽度,而不是将控件停靠在表单中。
确保控件在设计器中看起来正确,然后将其固定在右侧。如果调整窗体大小,这将停止剪切结束列。更好的是,添加一个面板来嵌入您的控件并相应地停靠它。
我希望这会有所帮助。
答案 1 :(得分:0)
将最后一列的“ AutoSizeMode”属性设置为“ AllCells”对我来说是固定的:
column.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;