我正在尝试让每个单元格的数据彼此正确对齐,但对于一列,内容与其他单元格不相符。我不知道为什么会这样,因为我查看了所有默认样式和其他布局/外观选项,没有什么是不寻常的。我不知道这是否有帮助,但这是在调试模式下运行的程序的屏幕截图。
这只是由于某种原因关闭的电子邮件列。如果需要,我可以尝试提供更多信息。
由于
我让其他人排队,但仍然遇到电子邮件列
的问题这真的令人沮丧,对我来说毫无意义。设计师代码是否有用于查看?如果需要,我可以提供。
更新 -
我注意到每个DGV上的第4列(电子邮件)。除第4列外,其他所有内容都排成一行。有什么想法吗?
更新2 -
以下是InitializeComponent方法中datagridview的代码:
//
// dataGridView
//
dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle1.Font = new System.Drawing.Font("Verdana", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
this.dataGridView.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle1;
this.dataGridView.AutoGenerateColumns = false;
this.dataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.AllCells;
this.dataGridView.AutoSizeRowsMode = System.Windows.Forms.DataGridViewAutoSizeRowsMode.AllCells;
this.dataGridView.BackgroundColor = System.Drawing.Color.White;
dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle2.BackColor = System.Drawing.SystemColors.Control;
dataGridViewCellStyle2.Font = new System.Drawing.Font("Verdana", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
dataGridViewCellStyle2.ForeColor = System.Drawing.SystemColors.WindowText;
dataGridViewCellStyle2.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle2.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle2.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
this.dataGridView.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle2;
this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.idDataGridViewTextBoxColumn,
this.firstnameDataGridViewTextBoxColumn,
this.lastnameDataGridViewTextBoxColumn,
this.phonenumberDataGridViewTextBoxColumn,
this.emailaddressDataGridViewTextBoxColumn,
this.birthdayDataGridViewTextBoxColumn,
this.addressDataGridViewTextBoxColumn,
this.marriedDataGridViewTextBoxColumn});
this.dataGridView.DataSource = this.headsBindingSource;
dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle3.BackColor = System.Drawing.SystemColors.Window;
dataGridViewCellStyle3.Font = new System.Drawing.Font("Verdana", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
dataGridViewCellStyle3.ForeColor = System.Drawing.SystemColors.ControlText;
dataGridViewCellStyle3.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle3.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle3.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
this.dataGridView.DefaultCellStyle = dataGridViewCellStyle3;
this.dataGridView.GridColor = System.Drawing.Color.Black;
this.dataGridView.Location = new System.Drawing.Point(20, 63);
this.dataGridView.Name = "dataGridView";
dataGridViewCellStyle4.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle4.BackColor = System.Drawing.SystemColors.Control;
dataGridViewCellStyle4.Font = new System.Drawing.Font("Verdana", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
dataGridViewCellStyle4.ForeColor = System.Drawing.SystemColors.WindowText;
dataGridViewCellStyle4.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle4.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle4.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
this.dataGridView.RowHeadersDefaultCellStyle = dataGridViewCellStyle4;
dataGridViewCellStyle5.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle5.Font = new System.Drawing.Font("Verdana", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
dataGridViewCellStyle5.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
this.dataGridView.RowsDefaultCellStyle = dataGridViewCellStyle5;
this.dataGridView.RowTemplate.DefaultCellStyle.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
this.dataGridView.RowTemplate.DefaultCellStyle.Font = new System.Drawing.Font("Verdana", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.dataGridView.RowTemplate.DefaultCellStyle.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
this.dataGridView.RowTemplate.Resizable = System.Windows.Forms.DataGridViewTriState.True;
this.dataGridView.Size = new System.Drawing.Size(1028, 426);
this.dataGridView.TabIndex = 0;
this.dataGridView.KeyDown += new System.Windows.Forms.KeyEventHandler(this.dataGridView_KeyDown);
和电子邮件专栏(第4栏)
// emailaddressDataGridViewTextBoxColumn
//
this.emailaddressDataGridViewTextBoxColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.AllCells;
this.emailaddressDataGridViewTextBoxColumn.DataPropertyName = "email_address";
this.emailaddressDataGridViewTextBoxColumn.HeaderText = "email_address";
this.emailaddressDataGridViewTextBoxColumn.Name = "emailaddressDataGridViewTextBoxColumn";
this.emailaddressDataGridViewTextBoxColumn.Width = 125;
//
我将整个解决方案放在Dropbox上,如果有人可以下载并查看它,将非常感谢 - https://www.dropbox.com/s/bh5if8b04eshpo9/QBC%20Members.zip?dl=0
答案 0 :(得分:1)
我将行的自动调整设置为false并添加了填充,并修复了对齐问题。不完全是我所希望的,但它会做。
答案 1 :(得分:0)
请尝试:
this.dataGridView1.Columns["Email"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
和标题:
this.dataGridView1.Columns[4].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleLeft;
希望这有帮助。