Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Lose detail in DGV that was entered via cellFormatting

Posted on 2009-06-29
2
Medium Priority
?
283 Views
Last Modified: 2012-05-07
Hi Experts

I am adding the contents of textbox to a cell in a DGV via  the cell formatting event.

The thing is when I try and obtain the value of that cell I get nothing.

http://www.screencast.com/users/si2030/folders/Jing/media/fe469369-a496-4729-8968-3989d55cd0a6


I have no idea why and have been working on this for a while now.

I have included the subroutine that the cell formatting event controller calls.

In particular this is the code that I am querying:

 If Me.dgvCreditorInvoiceDetail.Columns(e.ColumnIndex).Name = "ref" Then

                    If Presenter.validateAssetNo(e.Value) = True Then

                    Else

                        e.Value = txtInvoiceNumber.Text

                    End If

Now this works but when I use:

dgvCreditorInvoiceDetail.Rows(0).Cells("ref").Value
dgvCreditorInvoiceDetail.Item("ref", 0).Value

in both cases these return "nothing".

The cell clearly has an entry but the DGV thinks the cell has nothing in it.

Hope someone can tell me why the cell shows an entry but does not recognise that a value was in there.

Kind Regards

Simon
Private Sub formatDGVCells(ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Implements creditorInvoiceINTERFACE.IfrmCreditorInvoice.formatDGVCells
 
        Try
 
            If e.ColumnIndex > -1 Then
 
                If Me.dgvCreditorInvoiceDetail.Columns(e.ColumnIndex).Name = "amount" Then
 
                    If e.Value = "" Or IsNothing(e.Value) Then
 
                        e.Value = "$0.00"
                        e.CellStyle.ForeColor = Color.Black
 
                    Else
 
                        If (e.Value = 0) Then
 
                            e.Value = "$0.00"
                            e.CellStyle.ForeColor = Color.Black
 
                        Else
 
                            e.Value = "$" & FormatNumber((e.Value), 2, TriState.UseDefault, TriState.UseDefault, TriState.UseDefault)
 
                            If e.Value > 0 Then
 
                                e.CellStyle.ForeColor = Color.Black
 
                            Else
 
                                e.CellStyle.ForeColor = Color.Red
 
                            End If
 
                            Dim total As Decimal = 0
 
                            For count = 0 To dgvCreditorInvoiceDetail.Rows.Count - 1
 
                                total = total + CType(Mid(dgvCreditorInvoiceDetail.Rows(count).Cells("amount").Value, 1), Decimal)
 
                            Next
 
                            txtTotal.Text = String.Format("{0:C}", total)
 
                            If total < 0 Then
 
                                txtTotal.ForeColor = Color.Red
 
                            End If
 
                        End If
 
                    End If
 
                End If
 
                If Me.dgvCreditorInvoiceDetail.Columns(e.ColumnIndex).Name = "ref" Then
 
                    If Presenter.validateAssetNo(e.Value) = True Then
 
                    Else
 
                        e.Value = txtInvoiceNumber.Text
 
                    End If
 
                End If
 
                If Me.dgvCreditorInvoiceDetail.Columns(e.ColumnIndex).Name = "detail" Then
 
                    If e.Value <> "" Or (e.Value <> Nothing) Then
 
                        e.Value = e.Value.ToString.ToUpper
 
                    End If
 
                End If
 
                If Me.dgvCreditorInvoiceDetail.Columns(e.ColumnIndex).Name = "account" Then
 
                    newColumn.FlatStyle = FlatStyle.Flat
 
                End If
 
            End If
 
        Catch ex As Exception
 
            manageWindowsViewError("creditorTASK", "frmCreditorInvoicePayment", "formatDGVCells", ex)
 
        End Try
 
    End Sub

Open in new window

0
Comment
Question by:si2030
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 2000 total points
ID: 24741492
Does Cell.FormattedValue have any value?
0
 

Author Closing Comment

by:si2030
ID: 31597881
That simple! I didnt know that there was a "value" and... if you formatted the cell the formatted value. In this case there was no initial value so when I pulled the cells contents there was nothing!

Thanks.. great answer..
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question