Is there a way to center datagrid columns?

warrent

Member
Joined
Nov 19, 2005
Messages
12
Programming Experience
3-5
Is there a way to center datagrid columns without having to totally customize each column?
I figure there is some kind of .alignment attribute that I'm not finding.
 
Nevermind, I found the attribute I was looking for.
Here's an example of what I did.
This creates a new column, row, and DataGridTableStyle and puts it into a DataGrid.

Public table1 As New DataTable("rundata")
Public rpmcolumn As DataColumn = New DataColumn("RPM")
rpmcolumn.DataType = System.Type.GetType("System.Int64")
table1.Columns.Add(rpmcolumn)

Public ds As New DataSet
ds.Tables.Add(table1)
DataGrid.SetDataBinding(ds, "rundata")

Dim row As DataRow
row = table1.NewRow()
row.Item("RPM") = 2000
table1.Rows.Add(row)

Dim ts As New DataGridTableStyle
ts.MappingName = "rundata"
DataGrid.TableStyles.Clear()
DataGrid.TableStyles.Add(ts)
DataGrid.TableStyles("rundata").GridColumnStyles("RPM").Width = 75
DataGrid.TableStyles("rundata").GridColumnStyles("RPM").Alignment = HorizontalAlignment.Center
DataGrid.TableStyles("rundata").GridColumnStyles("RPM").NullText = ""

 
Back
Top