Individual Datagrid Column Width

M

Mike Fellows

Im trying to set the column width of individual datgrid columns
I can set the column widths of all the columns at once using

Me.DataGrid1.PreferredColumnWidth = 100

But I am unable to set the individual column widths

Also the source from where my data is coming from the first
column contains a date and time i.e. 01/01/2003 12:00:00
but within the datagrid it displays 01/01/2003 and i need it
to also show the time

Any help with this would be greatly appreciated

Regards

Michael Fellows
 
E

EricJ

this should help make sure you set the width for al the col's in the
datagrid

Dim ts As New DataGridTableStyle

ts.MappingName = "Table"

dgrMain.TableStyles.Clear()

dgrMain.SetDataBinding(dsForm, "Table")

dgrMain.TableStyles.Add(ts)

ts.GridColumnStyles(0).Width = 0

ts.GridColumnStyles(1).Width = 117

ts.GridColumnStyles(2).Width = 280

ts.GridColumnStyles(3).Width = 83

ts.AllowSorting = True

ts.AlternatingBackColor = Color.Lavender

ts.BackColor = Color.WhiteSmoke

ts.ForeColor = Color.MidnightBlue

ts.GridLineColor = Color.Gainsboro

ts.HeaderBackColor = Color.MidnightBlue

ts.HeaderForeColor = Color.WhiteSmoke

ts.LinkColor = Color.Navy

ts.SelectionBackColor = Color.Navy

ts.SelectionForeColor = Color.Lavender

ts.ColumnHeadersVisible = True
 
M

Mike Fellows

Thanks That worked great


Mike Fellows

EricJ said:
this should help make sure you set the width for al the col's in the
datagrid

Dim ts As New DataGridTableStyle

ts.MappingName = "Table"

dgrMain.TableStyles.Clear()

dgrMain.SetDataBinding(dsForm, "Table")

dgrMain.TableStyles.Add(ts)

ts.GridColumnStyles(0).Width = 0

ts.GridColumnStyles(1).Width = 117

ts.GridColumnStyles(2).Width = 280

ts.GridColumnStyles(3).Width = 83

ts.AllowSorting = True

ts.AlternatingBackColor = Color.Lavender

ts.BackColor = Color.WhiteSmoke

ts.ForeColor = Color.MidnightBlue

ts.GridLineColor = Color.Gainsboro

ts.HeaderBackColor = Color.MidnightBlue

ts.HeaderForeColor = Color.WhiteSmoke

ts.LinkColor = Color.Navy

ts.SelectionBackColor = Color.Navy

ts.SelectionForeColor = Color.Lavender

ts.ColumnHeadersVisible = True
 

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