Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
130
Format individual cell based on Row instead of a column
posted

Hi,

I have a webgrid (version 7.3.20073.1061) where I need to format the text in each cell based on the row instead of the column. That is because each column contains the Avg value for the month & the type of value is the Row. (The grid shows sulfur content by month in a cross-tab type format.)

So, this is what I have done within the InitializeRow event:

Dim oCellDecimal As UltraWebGrid.UltraGridCell = e.Row.Cells.FromKey("DisplayDecimals")
Dim intDecimals As Integer = 0
If Not (oCellDecimal Is Nothing) AndAlso Not (oCellDecimal.Text Is Nothing) AndAlso IsNumeric(oCellDecimal.Text) Then
 intDecimals = CInt(oCellDecimal.Text)
End If
For Each oCell As UltraWebGrid.UltraGridCell In e.Row.Cells
 'if the cell value is numeric & is one of the date or avg/min/max fields then set it's number of decimals accordingly
 If Not oCell.Value Is Nothing AndAlso oCell.Value.ToString.Length > 0 AndAlso IsNumeric(oCell.Value) Then
  Dim strFormat As String = "0.".PadRight(intDecimals + 2, "0")
                oCell.Text = Format(oCell.Value, strFormat)
 End If
Next

So each cell is rounded & displayed to the proper number of decimal places based on the values saved within the "DisplayDecimals" column.

However, if I get a number like "1.00" formatted, once the value gets to the screen, it shows up as "1". I am not setting any formatting at the column but it seems to still try to format it by stripping off the decimals places. 

Please help. Is there a way to over-ride the formating at the column level?

 

Thanks!

Parents
No Data
Reply
  • 130
    posted

    So, if I set the columns for my averages as "System.String" instead of "System.Double" my decimal places stay formatted. I did this via the InitializeLayout event of the grid as:

     UltraWebGrid.UltraGridColumn.DataType = "System.String"

    I'd rather keep my datatypes as is so I would appreciate any other solutions... Thanks.

     

    Tina

Children
No Data