How to change the column header in windows form datagrid

  • Thread starter appearinggalaxy
  • Start date
P

Peter Proost

Hi,

an other simple solution is to create a column alias in your select
statement:
for example: Select code as Number from table
will set the column header to Number

hth Peter
 
G

Ged Mead

I'm sure the previous answers will be all you need to get you fixed up, but
just in case you wanted an alternative, here is the kind of code I sometimes
use to tweak the GUI details of a DataGrid control:

' ----------- DataGrid
Formatting ----------------------------------------------------
' The following code formats the display of the DataGrid
' Create new Table Style.
Dim ts As New DataGridTableStyle
' Allocate it a mapping name
ts.MappingName = "Person" ' Note this is the same name as the Table
' Get rid of the default TableStyle
DataGrid1.TableStyles.Clear()
' Add this Style to the Collection
DataGrid1.TableStyles.Add(ts)

' You can tweak the TableStyle settings as you wish, eg:
ts.AlternatingBackColor = Color.LightBlue
ts.BackColor = Color.AliceBlue
ts.HeaderBackColor = Color.SkyBlue

' You can Assign New Widths and Col Header Text to DataGrid columns.
With DataGrid1.TableStyles("Person") '
..GridColumnStyles(0).Width = 75 ' First column, width
..GridColumnStyles(0).HeaderText() = "First Name(s)" ' First column, Col
Header text
..GridColumnStyles(1).Width = 25 ' Second column
..GridColumnStyles(1).HeaderText = "Init"
' you can change the width, but leave the text alone:
..GridColumnStyles(8).Width = 200

' You can hide a Column from the user, but still have it available
..GridColumnStyles(9).Width = 0
..GridColumnStyles(9).HeaderText() = "ID" ' Not seen
End With
 

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