Click here to Skip to main content
15,908,901 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have a datagridview in a windows forms vb.net application. My goal is to have any number over 0.999999999999 12 significant digits to be rounded down to 0.99999999999 11 significant digits. I want to prevent vb.net from rounding these values up to 1. This is how I'm implementing this but I can't figure out which DataGridView Event handler to use.

VB
If DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value <= 0.999999999999 Then
                DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value = 0.99999999999
            End If
Posted
Comments
Sergey Alexandrovich Kryukov 29-Apr-14 18:37pm    
This piece of code looks like such an abuse! :-)
—SA

1 solution

You could add an handler to your DataGridView.CellFormatting event; this way you can customize the formatted value (the way the DataGridView will present the data for a specific cell).

It may give something like:
VB
Private Sub DataGridView1_CellFormatting(sender As Object, e As DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting
   If (e.ColumnIndex = 4) Then '' Here I assume that your column is the fifth
      If (e.Value Is Not Nothing) Then
         Dim stringValue As String = e.Value.ToString("0.00000000000")
         e.Value = stringValue
         e.FormattingApplied = True
      End If
   End If
End Sub

Hope this helps. I apologize in advance for any mistake I could have done with VB, as I gave up this language about ten years ago.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900