Datagrid column width.

A

Alundra

Hi all,
I've been coding Java programs for several years, this is the first time I
code in vb.net. (No experience in coding using vb).
I use visual studio .net 2003.
I use a DataTable to store data from database and display it using a
DataGrid control. I use DataGridTableStyle and DataGridColumnStyle to
display customized column headers and checkbox for data of "Boolean" type.
So far so good, however I cannot find a way to adjust column width for each
field.
My Question is:
Is it possible to specify width for each DataGridColumnStyle?
Even better, is it possible to make columns adjust the width to fit the
longest content automatically?

Thanks in advance.

Mike
 
E

Earl

Dim tblStyle As New DataGridTableStyle

tblStyle.MappingName = "dtLaborCosts"
dgLaborHistory.TableStyles.Clear()
dgLaborHistory.TableStyles.Add(tblStyle)
Dim tbcLaborEntry As DataGridTextBoxColumn =
CType(tblStyle.GridColumnStyles("LaborEntryDate"), DataGridTextBoxColumn)
tbcLaborEntry.Alignment = HorizontalAlignment.Center
tbcLaborEntry.HeaderText = "Entry date"
tbcLaborEntry.Width = 60
tbcLaborEntry.NullText = ""
 
A

Alundra

Ok, I find the way to adjust the column width. Still don't know how to
adjust width automatically.
 
E

Earl

I'm not aware of a specific setting, nor have I ever used this, but I could
envision doing it like so .....

Dim intColTextWidth as Integer
intColTextWidth = dt.Tables("dts").Columns("YourColumn").MaxLength
.....
tbc.Width = intColTextWidth
 
A

Alundra

Thanks. I find the way to adjust the width, same as your method.
Still searching for ajusting it automatically. I have been searching the web
for a while, so far, only know I can use Font to calculate width of the
content and adjust the width accordingly. I guess there might be better way
to do it.
Thanks anyway.

: )
 
A

Alundra

Thanks for your reply. But I want to adjust the column width to maximum
content width, but the maximum width allowed.
In my case, the database width is 50, but usually the content width is
around 10.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top