We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

How to centre align data grid's header only

Thread ID:

Created:

Updated:

Platform:

Replies:

4634 May 21,2003 09:59 PM May 23,2004 09:54 AM Windows Forms 1
loading
Tags: FAQ
ANRao
Asked On May 21, 2003 09:59 PM

How to change the alignment of datagrids header to centre without disturbing the alignment of data in the rows. if i use tablestyles and set alignment of columns its affecting alignment of all rows and header. i want to centre align the header and the data may be aligned left/right depending on the data type.

Jeff
Replied On May 23, 2004 09:54 AM

Ok, My problem is that I am only able to align headers. Here is my procedure. Private Sub AddCellFormattingColumnStyles2(ByVal grid As DataGrid, ByVal handler As FormatCellEventHandler) Dim ts As DataGridTableStyle ts = New DataGridTableStyle Dim dt As DataTable dt = CType(grid.DataSource, DataTable) ts.MappingName = dt.TableName Dim j As Integer j = 0 Do While (j < dt.Columns.Count) Dim cs As DataGridFormattableTextBoxColumn cs = New DataGridFormattableTextBoxColumn(j) cs.Alignment = HorizontalAlignment.Right cs.MappingName = dt.Columns(j).ColumnName cs.HeaderText = dt.Columns(j).ColumnName ''cs.Alignment = HorizontalAlignment.Right ''cs.Width = -1 AddHandler cs.SetCellFormat, handler ts.GridColumnStyles.Add(cs) j = (j + 1) Loop grid.TableStyles.Clear() grid.TableStyles.Add(ts) Dim z As Int32 z = 0 For z = 0 To dt.Columns.Count - 1 grid.TableStyles(0).GridColumnStyles(z).ReadOnly = True Select Case z Case 0 grid.TableStyles(0).GridColumnStyles(z).Width = 250 ''grid.TableStyles(0).GridColumnStyles(z).Alignment = HorizontalAlignment.Right Case Else grid.TableStyles(0).GridColumnStyles(z).Width = 150 ''grid.TableStyles(0).GridColumnStyles(z).Alignment = HorizontalAlignment.Right End Select Next grid.TableStyles(0).AllowSorting = False grid.TableStyles(0).SelectionBackColor = System.Drawing.Color.Gold End Sub Hope this helps if not message me back. >How to change the alignment of datagrids header to centre without disturbing the alignment of data in the rows. if i use tablestyles and set alignment of columns its affecting alignment of all rows and header. i want to centre align the header and the data may be aligned left/right depending on the data type.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;