I thought I had done this before, but I'm apparently overlooking something.
All I want to do is set the alignment of the first column to the right. The
dataset gives me 5 columns and will auto-format the grid, but I really want
to align just one column. Thus the code below. However, the app blows right
past my attempt to impose a new table style and auto-formats the grid with
everything aligned to the left (I have deleted all table styles from the
Datagrid properties, so there is no "default").

Is it possible to set alignment for one column or do ALL need to be manually
aligned? Anything else I'm overlooking?

DataGrid1.TableStyles.Clear()
Dim tblStyle As New DataGridTableStyle
tblStyle.MappingName = "History"
Dim dgColumn1 As New DataGridTextBoxColumn
Dim dgColStyleRight As DataGridColumnStyle
dgColumn1 = New DataGridTextBoxColumn
dgColumn1.Alignment = System.Windows.Forms.HorizontalAlignment.Center
tblStyle.GridColumnStyles.Add(dgColumn1)
DataGrid1.CaptionText = "History"
DataGrid1.ReadOnly = True
DataGrid1.TableStyles.Add(tblStyle)

Re: Changing alignment of column in datagrid by ClayB

ClayB
Wed Jun 02 13:06:06 CDT 2004

You can create a TableStyle, and then add it to the datagrid's tableStyles
collection. This will allow you to directly access the default
GridColumnStyle objects for each of the default columns. There, you can
explicitly set the properties on teh default columns without having to
explecitly add GridColumnStyles for every column.

Me.dataGrid1.DataSource = dt ' some DataTable...

Dim tblStyle As New DataGridTableStyle()
tblStyle.MappingName = dt.TableName

Me.dataGrid1.TableStyles.Clear()
Me.dataGrid1.TableStyles.Add(tblStyle)

Dim tbc As DataGridTextBoxColumn =
CType(tblStyle.GridColumnStyles("Col1"), DataGridTextBoxColumn)
tbc.Alignment = HorizontalAlignment.Center

======================
Clay Burch, .NET MVP

Visit www.syncfusion.com for the coolest tools

"Earl comcast net>" <brikshoe<at.> wrote in message
news:OO6bjcMSEHA.3628@TK2MSFTNGP12.phx.gbl...
> I thought I had done this before, but I'm apparently overlooking
something.
> All I want to do is set the alignment of the first column to the right.
The
> dataset gives me 5 columns and will auto-format the grid, but I really
want
> to align just one column. Thus the code below. However, the app blows
right
> past my attempt to impose a new table style and auto-formats the grid with
> everything aligned to the left (I have deleted all table styles from the
> Datagrid properties, so there is no "default").
>
> Is it possible to set alignment for one column or do ALL need to be
manually
> aligned? Anything else I'm overlooking?
>
> DataGrid1.TableStyles.Clear()
> Dim tblStyle As New DataGridTableStyle
> tblStyle.MappingName = "History"
> Dim dgColumn1 As New DataGridTextBoxColumn
> Dim dgColStyleRight As DataGridColumnStyle
> dgColumn1 = New DataGridTextBoxColumn
> dgColumn1.Alignment = System.Windows.Forms.HorizontalAlignment.Center
> tblStyle.GridColumnStyles.Add(dgColumn1)
> DataGrid1.CaptionText = "History"
> DataGrid1.ReadOnly = True
> DataGrid1.TableStyles.Add(tblStyle)
>
>



Re: Changing alignment of column in datagrid by Earl

Earl
Wed Jun 02 14:04:40 CDT 2004

Thanks Clay.

"ClayB [Syncfusion]" <clayb@syncfusion.com> wrote in message
news:uWHyGxMSEHA.2704@TK2MSFTNGP10.phx.gbl...
> You can create a TableStyle, and then add it to the datagrid's tableStyles
> collection. This will allow you to directly access the default
> GridColumnStyle objects for each of the default columns. There, you can
> explicitly set the properties on teh default columns without having to
> explecitly add GridColumnStyles for every column.
>
> Me.dataGrid1.DataSource = dt ' some DataTable...
>
> Dim tblStyle As New DataGridTableStyle()
> tblStyle.MappingName = dt.TableName
>
> Me.dataGrid1.TableStyles.Clear()
> Me.dataGrid1.TableStyles.Add(tblStyle)
>
> Dim tbc As DataGridTextBoxColumn =
> CType(tblStyle.GridColumnStyles("Col1"), DataGridTextBoxColumn)
> tbc.Alignment = HorizontalAlignment.Center
>
> ======================
> Clay Burch, .NET MVP
>
> Visit www.syncfusion.com for the coolest tools
>
> "Earl comcast net>" <brikshoe<at.> wrote in message
> news:OO6bjcMSEHA.3628@TK2MSFTNGP12.phx.gbl...
> > I thought I had done this before, but I'm apparently overlooking
> something.
> > All I want to do is set the alignment of the first column to the right.
> The
> > dataset gives me 5 columns and will auto-format the grid, but I really
> want
> > to align just one column. Thus the code below. However, the app blows
> right
> > past my attempt to impose a new table style and auto-formats the grid
with
> > everything aligned to the left (I have deleted all table styles from the
> > Datagrid properties, so there is no "default").
> >
> > Is it possible to set alignment for one column or do ALL need to be
> manually
> > aligned? Anything else I'm overlooking?
> >
> > DataGrid1.TableStyles.Clear()
> > Dim tblStyle As New DataGridTableStyle
> > tblStyle.MappingName = "History"
> > Dim dgColumn1 As New DataGridTextBoxColumn
> > Dim dgColStyleRight As DataGridColumnStyle
> > dgColumn1 = New DataGridTextBoxColumn
> > dgColumn1.Alignment = System.Windows.Forms.HorizontalAlignment.Center
> > tblStyle.GridColumnStyles.Add(dgColumn1)
> > DataGrid1.CaptionText = "History"
> > DataGrid1.ReadOnly = True
> > DataGrid1.TableStyles.Add(tblStyle)
> >
> >
>
>