CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2006
    Location
    Mnila, Philippines
    Posts
    171

    Hide the true value of datagridview cell

    I just want to ask guys if there is a property of datagridview that will automatically formats the value of each cell but it will go back into original value before the user edits its data. This is only applicable for double datatype.

    example. the value of the cell is 12908.21232311. But the datagrid will show only 12908.2123.
    And when the user edits the cell, the 12908.2123 will go back to its original form 12908.21232311. And when the user changed the value of 12908.21232311 into
    12908.44444444, it will format again into 4 decimal places which is 12908.4444


    Thanks guys

  2. #2
    Join Date
    Jul 2006
    Location
    Mnila, Philippines
    Posts
    171

    Re: Hide the true value of datagridview cell

    Code:
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Me.DataGridView1.Rows.Add(123.22222, 33333.3221)
        End Sub
    
        Private Sub DataGridView1_CellBeginEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellCancelEventArgs) Handles DataGridView1.CellBeginEdit
            Me.DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Style.Format = Nothing
    
        End Sub
    
        Private Sub DataGridView1_CellEndEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit
            Me.DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Style.Format = "N2"
        End Sub

    but the problem is when I finished edited the value, it will not format the cell in 2 decimal places.

  3. #3
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Hide the true value of datagridview cell

    Something like this:

    Code:
           DataGridView1.Columns(3).HeaderText = "Payment (Total: " + FormatCurrency(totalsum(3)).ToString & ")"
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured