Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TableStyle won't set in DataGrid 1

Status
Not open for further replies.

dpdoug

Programmer
Nov 27, 2002
455
US
My DataGridTableStyle will absolutely not set the styles whether I set them with the Properties page or in code.

Whether I set the TableStyles or not it displays the same way -- all the columns are aligned to the left and they are all the same width -- no matter how or where I set them.

Here's where I tried setting them in code:
Code:
Dim dgStyle As DataGridTableStyle = New DataGridTableStyle()
Dim textColumn As New DataGridTextBoxColumn()

dgStyle.GridColumnStyles.Clear()

'ShellID
textColumn.MappingName = "ID"
textColumn.HeaderText = "ID"
textColumn.Width = 2
textColumn.ReadOnly = True
dgStyle.GridColumnStyles.Add(textColumn)
'PurchaseOrder
textColumn.MappingName = "PurchaseOrder"
textColumn.HeaderText = "PO"
textColumn.Width = 80
textColumn.Alignment = HorizontalAlignment.Left
textColumn.ReadOnly = True
dgStyle.GridColumnStyles.Add(textColumn)
'Reason
textColumn.MappingName = "Reason"
textColumn.HeaderText = "Rsn"
textColumn.Width = 40
textColumn.Alignment = HorizontalAlignment.Center
textColumn.ReadOnly = True
dgStyle.GridColumnStyles.Add(textColumn)

'BeginBill
textColumn.MappingName = "BeginBill"
textColumn.HeaderText = "StartDate"
textColumn.Width = 60
textColumn.Alignment = HorizontalAlignment.Center
textColumn.ReadOnly = True
dgStyle.GridColumnStyles.Add(textColumn)
...
...
...
DataGrid1.TableStyles.Add(dgStyle)

The data displays fine -- except with no formatting.
 
I believe that this should do it:

dgStyle.MappingName = "MyTable"

"MyTable" ought to be the name you've used in the DataSet designer. Because the DataGrid can potentially display several different tables, it needs to figure out which style to apply. If it can't find a match, it autogenerates one.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top