• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 969
  • Last Modified:

Change datagridview column 0 width.

Hi,

I have windows form with datagridview.
I need to change the width of column 0.
Why below code doesn't work?

.Columns(0).Width = 5

Thank you.
0
emi_sastra
Asked:
emi_sastra
  • 2
  • 2
1 Solution
 
Wayne Taylor (webtubbs)AstronautCommented:
The Column index is a zero based array, meaning 0 is the first column, 1 is the second, etc. If you wish to change the Row Header, use this....

    DataGridView1.RowHeadersWidth = 5

...otherwise, to change the width of the first column, this works fine....

    DataGridView1.Columns(0).Width = 5

Regards,

Wayne
0
 
emi_sastraAuthor Commented:
Hi Wayne,

It works use:
1. DataGridView1.RowHeadersWidth = 5

but not:
2. DataGridView1.Columns(0).Width = 5

Why is that, the 2nd method works for other columsn?

Thank you.



0
 
Wayne Taylor (webtubbs)AstronautCommented:
The second method works for columns. The First method works for RowHeaders. The RowHeader (they gray area to the left of each row) is NOT the first column.

Wayne
0
 
emi_sastraAuthor Commented:
I see.

Thank you very much for your help.
0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now