Replace the field column name

knockyo

Well-known member
Joined
Sep 20, 2006
Messages
78
Programming Experience
1-3
Below is my TableA, but i dont want show the P001, P002, ...... for the my datagrid header

field01ll3.jpg


because i need to link below TableB,
field02nt5.jpg


so, finally my datagrid header, P001 with replace with Vlow, P002 --> VHigh........

is that possible?
 
Hey knockyo, im not sure if you're trying to say you want to do this automatically somehow.. but you can do it by creating a DataGridTableStyle before binding your grid to your DataSource. The table style has a collection of DataGridColumnStyle objects - each of which have a property called HeaderText.

Have a look at the following code:

VB.NET:
[COLOR="Blue"]Dim [/COLOR]dc [COLOR="Blue"]As [/COLOR]DataColumn
[COLOR="Blue"]Dim [/COLOR]dgtc [COLOR="Blue"]As [/COLOR]DataGridReadOnlyTextBoxColumn

[COLOR="Green"]'setup datagrids[/COLOR]
[COLOR="Blue"]Dim[/COLOR] ts [COLOR="Blue"]As New [/COLOR]DataGridTableStyle()
ts.RowHeadersVisible = [COLOR="Blue"]False[/COLOR]
ts.MappingName = "tbl_events"
ts.AlternatingBackColor = Color.FromArgb(239,239,239)
dgEvents.TableStyles.Add(ts)

[COLOR="Green"]'column timestamp[/COLOR]
dgtc = [COLOR="Blue"]New [/COLOR]DataGridTextBoxColumn()
dgtc.MappingName = "timestamp"
dgtc.Width = 40
dgtc.HeaderText = "COLUMN HEADER HERE!"
tsEvents.GridColumnStyles.Add(dgtc)

You can save a reference to the DataGridTextBoxColumn objects and then set the HeaderText value whenever you need to in code.

One point tho, you will need to create and configure the TableStyle before you bind to your datasource!

Hope this helps
mafro
 
Back
Top