Setting Bound Grid Column Width

T

Tim Nelson

I thought there should be simple way of setting the column width in the
a DataGrid. I've set up a table style (properties tab) that lengthen the
columns,
but I can't seem to bind this table style to the grid (or it's columns I
guess). No
matter what I do the grid keeps a standard column size for each column.
Can anyone throw me a bone here?
Thanks.
 
W

William Ryan eMVP

It's probably the columnmappings. Are you adding the TableStyle and
ColumnStyle before you bind or after: Try this....

dg.SuspendLayout()

Const ng As String = "NOT GIVEN"

Dim tsMain As New DataGridTableStyle

tsMain.MappingName = AllData.Tbl_Job_Tracking.TableName

'Work Type Column

Dim csWorkType As DataGridTextBoxColumn = New DataGridTextBoxColumn

csWorkType.MappingName = AllData.Tbl_Job_Tracking.Columns(0).ColumnName

csWorkType.HeaderText = "Work Type"

csWorkType.Width = 70

tsMain.GridColumnStyles.Add(csWorkType)

'Job Number Column

Dim csJobNumber As New DataGridTextBoxColumn

csJobNumber.MappingName = AllData.Tbl_Job_Tracking.Columns(1).ColumnName

csJobNumber.HeaderText = "Job #"

csJobNumber.Width = 65

csJobNumber.NullText = ng

tsMain.GridColumnStyles.Add(csJobNumber)



tsMain.GridColumnStyles.Add(csDeleteResp)

dg.TableStyles.Add(tsMain)

dg.ResumeLayout()
 
T

Tim Nelson

William,
Thanks for the reply. I thought I could do this at design time and wouldn't
need to resort to my own code to do this. I basically have two fields
from a table one 40 characters and one 10 characters. I just want to
column that holds the 40 character to be lengthened so it displays
the whole value. I will try what you said. Thanks.
 

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