Column cell value in datagridview is not consistent with others

I am trying to get the data for each cell in order to be consistent with each other, but for one column the content does not line up with the others. I am not sure why this is so, since I looked through all the default styles and other layout / appearance options, and nothing unusual. I don’t know if this will help, but here is a screenshot of a program running in debug mode.

enter image description here

This is just an email column that is disabled for some reason. I can try to provide additional information if necessary.

thanks

I got the rest to line up, but still having issues with email columns

enter image description here

This is really frustrating and makes no sense to me. Could constructor code be useful to take a look? I can provide it if required.

Update -

I noticed his fourth column (via email) on every DGV. Everything else is aligned correctly, except for the fourth column. Any ideas?

Update 2 -

Here is the code that is intended for datagridview inside the InitializeComponent method:

// // 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); 

and email column (4th column)

 // 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; // 

I put the whole solution on Dropbox, if someone can download it and check it out, I would really appreciate it - https://www.dropbox.com/s/bh5if8b04eshpo9/QBC%20Members.zip?dl=0 p>

+5
source share
2 answers

I set the autosave of the lines to false and added an add-on and it fixed alignment problems. Not quite what I was hoping for, but it will be done.

+1
source

Try:

 this.dataGridView1.Columns["Email"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft; 

and for the title:

 this.dataGridView1.Columns[4].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleLeft; 

Hope this helps.

0
source

Source: https://habr.com/ru/post/1273023/


All Articles