Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataGridView Fixed Width Coulmns Different Size on Client's Computer

Status
Not open for further replies.

Auguy

Programmer
May 1, 2004
1,206
US
VB.Net 2008 with SQL 2005. Some of my forms and data grid views don't display properly on client's Win 7 computer. Let's deal with the grid first. Here's the cod on the Form load.
Code:
dgvParcel.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None
dgvParcel.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None
dgvParcel.EnableHeadersVisualStyles = False
dgvParcel.RowHeadersWidth = 22
Her's the code in my refresh data sub
Code:
dsParcel.Clear()
dsParcel = ParcelSelect(CurrentTaxYear, other filter items here, .......)
dgvParcel.DataSource = dsParcel.Tables(0)
dgvParcel.Columns("EditCount").Visible = False

dgvParcel.Columns("ParcelNo").HeaderText = "Parcel #"
dgvParcel.Columns("ParcelNo").Width = 65

dgvParcel.Columns("StreetNo").HeaderText = "Street #"
dgvParcel.Columns("StreetNo").Width = 40
Now, all of this displays properly on my machine, but on the client's computer the ParcelNo column is always too narrow to display the contents. All of the ParcelNo entries are the same length. In the designer I have set the CellStyle font to Microsoft Sans Serif, 8.25pt. Am I doing something wrong here? Is it a Font issue?

Auguy
Sylvania/Toledo Ohio
 
I usually do something like this:

Code:
dgvParcel.Columns("ParcelNo").HeaderText = "Parcel #"
dgvParcel.Columns("ParcelNo").Width = [blue]dgvParcel.Width * 0.2[/blue]

dgvParcel.Columns("StreetNo").HeaderText = "Street #"
dgvParcel.Columns("StreetNo").Width = [blue]dgvParcel.Width * 0.18 [/blue]

My column width is relative to the width of the data grid.

Your 65 and 40 may be different depending on monitor’s resolution settings

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Thanks, I might try that if I don't come up with another solution. One question with your solution, do the columns change size if the grid is resized?

Auguy
Sylvania/Toledo Ohio
 
It all depends (standard consultant answer :) ) on where you place this code.

If you want to assign the column widths and allow user to resize them and keep what user wants, then I would place this code in Form_Load.

If you want to alawys force the column widths, I wuld put it in Resize event for grid.

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top