LarryZ
asked on
Center header text if column is right-justified in DataGrid
Hello Experts.
I have a DataGrid in a Windows form and am successfully controling column width and column alignment in code using DataGridTableStyles and GridColumnStyles - no problem. Column 1 ( width = 90) contains numeric data, so I used
dgts.GridColumnStyles(1).A lignment = HorizontalAlignment.Right
to make the data right-justifed. The data looks good in the column, but the 3-character Header Text doesn't look very good when it is also right-justified - it looks like it is crammed too far to the right. I would like to center-justify the Header Text, but still leave the column data right-justified.
I unsuccessfully tried using the PadRight method like this:
Dim strCol1Header As String = "UPC"
dgts.GridColumnStyles(1).H eaderText = strCol1Header.PadLeft(9)
Does anyone know a way to have different justification for the Header Text and column data in a Windows-form DataGrid?
I have a DataGrid in a Windows form and am successfully controling column width and column alignment in code using DataGridTableStyles and GridColumnStyles - no problem. Column 1 ( width = 90) contains numeric data, so I used
dgts.GridColumnStyles(1).A
to make the data right-justifed. The data looks good in the column, but the 3-character Header Text doesn't look very good when it is also right-justified - it looks like it is crammed too far to the right. I would like to center-justify the Header Text, but still leave the column data right-justified.
I unsuccessfully tried using the PadRight method like this:
Dim strCol1Header As String = "UPC"
dgts.GridColumnStyles(1).H
Does anyone know a way to have different justification for the Header Text and column data in a Windows-form DataGrid?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
jpinia, my question referred to DataGrids on Windows forms, not Web forms. Your answer seems like HTML for Web page.
I think there is no option in Window forms for that
ASKER
I figured out a sloppy workaround, but I don't like it much:
dgts.GridColumnStyles(1).H eaderText = "UPC" & Chr(32) & Chr(32) & Chr(32) & Chr(32) & Chr(32) & Chr(32) & Chr(32) & Chr(32) & Chr(31)
This seems to pad the region to the right of the "UPC" heading with invisible characters.
dgts.GridColumnStyles(1).H
This seems to pad the region to the right of the "UPC" heading with invisible characters.
Like this,
<HeaderStyle Font-Bold="True" HorizontalAlign=Center ForeColor="White"></Header
Regards
JP