How to change width of DataGridView Columns

.net, datagridview, vb.net, width

Solution

Check that you do not have code to change it back (perhaps in the `ColumnWidthChanged` event); and check if `AutoSizeColumnsMode` is on. Also, you can iterate columns rather than do it individually:

For Each c As DataGridViewColumn In DataGridView1.Columns
    c.Width = 50
Next

Problem

I have a vb.net windows forms application with a datagridview. I'm hoping to find a way to change the width for multiple columns in a datagridview. This is what I have so far, but it only changes the width for the first column not the rest. I appreciate any help you may give. ``` Dim columnwidth1 As DataGridViewColumn = DataGridView1.Columns(0) columnwidth1.Width = 100 Dim columnwidth2 As DataGridViewColumn = DataGridView1.Columns(1) columnwidth2.Width = 100 Dim columnwidth3 As DataGridViewColumn = DataGridView1.Columns(2) columnwidth3.Width = 100 Dim columnwidth4 As DataGridViewColumn = DataGridView1.Columns(3) columnwidth4.Width = 100 ```

Original source