DataGridView - unable to change column widths in Design Mode or Runtime

Hi Experts,

I have a DataGridView control for which I am unable to change column widths - either in Design Mode or Runtime.

Here are it's Properties:

        Me.dgvLayeredSystem.AllowUserToAddRows = False
        Me.dgvLayeredSystem.AllowUserToDeleteRows = False
        Me.dgvLayeredSystem.AutoGenerateColumns = False
        Me.dgvLayeredSystem.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.AllCells
        DataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft
        DataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Control
        DataGridViewCellStyle1.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        DataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText
        DataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight
        DataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText
        DataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.[True]
        Me.dgvLayeredSystem.ColumnHeadersDefaultCellStyle = DataGridViewCellStyle1
        Me.dgvLayeredSystem.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize
        Me.dgvLayeredSystem.Columns.AddRange(New System.Windows.Forms.DataGridViewColumn() {Me.LayeredSystemIDDataGridViewTextBoxColumn, Me.LayeredSystemTitleDataGridViewTextBoxColumn})
        Me.dgvLayeredSystem.DataSource = Me.LayeredSystemsBindingSource
        DataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft
        DataGridViewCellStyle2.BackColor = System.Drawing.SystemColors.Window
        DataGridViewCellStyle2.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        DataGridViewCellStyle2.ForeColor = System.Drawing.SystemColors.ControlText
        DataGridViewCellStyle2.SelectionBackColor = System.Drawing.SystemColors.Highlight
        DataGridViewCellStyle2.SelectionForeColor = System.Drawing.SystemColors.HighlightText
        DataGridViewCellStyle2.WrapMode = System.Windows.Forms.DataGridViewTriState.[False]
        Me.dgvLayeredSystem.DefaultCellStyle = DataGridViewCellStyle2
        Me.dgvLayeredSystem.Dock = System.Windows.Forms.DockStyle.Fill
        Me.dgvLayeredSystem.Location = New System.Drawing.Point(0, 0)
        Me.dgvLayeredSystem.Name = "dgvLayeredSystem"
        DataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft
        DataGridViewCellStyle3.BackColor = System.Drawing.SystemColors.Control
        DataGridViewCellStyle3.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        DataGridViewCellStyle3.ForeColor = System.Drawing.SystemColors.WindowText
        DataGridViewCellStyle3.SelectionBackColor = System.Drawing.SystemColors.Highlight
        DataGridViewCellStyle3.SelectionForeColor = System.Drawing.SystemColors.HighlightText
        DataGridViewCellStyle3.WrapMode = System.Windows.Forms.DataGridViewTriState.[True]
        Me.dgvLayeredSystem.RowHeadersDefaultCellStyle = DataGridViewCellStyle3
        Me.dgvLayeredSystem.Size = New System.Drawing.Size(657, 235)
        Me.dgvLayeredSystem.TabIndex = 0

Open in new window

Hope that's enough detail to sort this out?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jacques Bourgeois (James Burger)PresidentCommented:
Columns cannot be adjusted by the user when you set the AutoSizeColumnsMode to AllCells. Since you are doing it at the grid level, all the columns get that value and none is adjustable. This makes sense if you think of it. There would be a contradiction between autosizing and user sizing.

What I do is use AllCells only for columns that hold some kind of fixed data where I am quite sure that the user won't need to enlarge them. Could be an ID whose number of digits will grow during the life of the application. Or a date, that can change width depending on the Control Panel settings.

For all the other columns, I set a Width that is good for most situations, leaving the AutoSizeMode to None so that the user can enlarge the columns if needed.

That works very well in most instances.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LeighWardleAuthor Commented:
Many thanks, James.
Regards, Leigh
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.