formatting data in a datagrid

  • Thread starter Thread starter Robert Smith
  • Start date Start date
R

Robert Smith

Hello,

I have a datagrid bound to a dataset like so

Public Sub BindGrid(ByVal dgtrusses As DataGrid,
ByRef MyTable As DataTable)
dgtrusse.DataSource = MyTable
cm = CType(BindingContext(MyTable),
CurrencyManager)

End Sub


ts = New DataGridTableStyle(cm)
'new code to format the column
ts.MappingName = "trusses"

dgtrusses.TableStyles.Add(ts)


'B/C
ts.GridColumnStyles(11).Width = 50
ts.GridColumnStyles(11).HeaderText = "B/C"
ts.GridColumnStyles(11).NullText = ""

This is all fine except I wan't to format the 11th column
above to just show 3 decimal places, how do I do this do i
introduce a new gridcolumnstyle, if so how.

Regards
Robert
 
You need to set the format property of the DataGridTextBoxColumn

You'll need to check what string you'll need to show 3 decimal places
it might be something like "D3".

But for something I was doing I wanted a decimal to show as a percent
w/ 2 decimal places and the string I used was "P2":

Dim PercentColumn as DataGridTextBoxColumn
PercentColumn.Format = "p2"

Hopefully this will give a little to start hunting for what you need.
Rounding may also cause an issue. Good Luck.
 
Back
Top