2 Replies - 2554 Views - Last Post: 16 February 2011 - 05:57 AM Rate Topic: -----

#1 November-06  Icon User is offline

  • D.I.C Regular

Reputation: 46
  • View blog
  • Posts: 407
  • Joined: 04-January 11

Removing ErrrorText in DataGridView Cell. Code was woking before but n

Posted 12 February 2011 - 10:53 AM

What I want to do is remove the errortext once the data input is valid.

I have a code that works perfectly fine. I had run it a number of times and its working properly the whole time. But after I restarted my computer, there seem to have been an error.

The thing is... I created validations in a cell of a DataGridView. It will show an error text if it's empty, if it's non-numeric, and if there is a repetition on my primary key.

The problem is, after displaying the error text on invalid data, it won't disappear even the data reentered is valid.

It was solved before as I set the .ErrorText to "".

But the next time I ran it, it wouldn't work.

I have 4 datagridview that uses the same code but only one of the 4 is not working properly.

my code goes like this...
Try
            If ValidateLivingDataType() = True Then
                AssureLivingHasError = False
                grid_LivingBenefits.CurrentCell.ErrorText = ""
                If grid_LivingBenefits.Columns(ColumnIndex).Name = "End of Policy Year" Then
                    If ValidateLivingPrimaryKey() = False Then
                        AssureLivingHasError = True
                        grid_LivingBenefits.CurrentCell.ErrorText = "There should be NO DUPLICATE VALUES in the column, 'End of Policy Year'."
                    End If
                Else
                    AddValuesInLivingTable()
                End If
            Else
                AssureLivingHasError = True
                grid_LivingBenefits.CurrentCell.ErrorText = "Insert a Numeric Input."
            End If
        Catch ex As Exception
            AssureLivingHasError = True
            grid_LivingBenefits.CurrentCell.ErrorText = "Insert a Numeric Input."
        End Try


Another odd thing is... although the columns 2,3,4,6 uses the same condition and statement, column 6 is the only one working.

This post has been edited by modi123_1: 12 February 2011 - 12:13 PM
Reason for edit:: please use code tags


Is This A Good Question/Topic? 0
  • +

Replies To: Removing ErrrorText in DataGridView Cell. Code was woking before but n

#2 November-06  Icon User is offline

  • D.I.C Regular

Reputation: 46
  • View blog
  • Posts: 407
  • Joined: 04-January 11

Re: Removing ErrrorText in DataGridView Cell. Code was woking before but n

Posted 12 February 2011 - 08:32 PM

I experimented with the codes some more and found out that the codes are not the problem at all.

When the administrator deletes all the rows in the database, this happens.

The errortext is supposed to read the datagridview cell not the cell in the database. Although using messageboxes I found out that the program can still read the cell data, it still displays an error message.

When I replaced the updated database with the back-up of my original database, the error is not there anymore.

I have a subroutine in another form that deletes all the database rows.

Then it should add all rows in the datagridview to the database in access.

There's no problem with deleting but the adding of new row is not working.

The code goes like this...


 Dim ALBAdapter As New OleDbDataAdapter
        Dim ds_ALB As New DataSet
        Dim dr_ALB As DataRow

        'Clears Data in the database
        If Assure_Benefits.LivingHasError = False Then
            ALBAdapter = New OleDbDataAdapter("Select * from Assure_LivingBenefits", LogIn.DBConnection)
            ALBAdapter.Fill(ds_ALB, "Assure_LivingBenefits")
            Dim RowCount As Integer = ds_ALB.Tables("Assure_LivingBenefits").Rows.Count
            Dim RowCTR As Integer = 0
            Do Until RowCount = 0
                ds_ALB.Tables("Assure_LivingBenefits").Rows(RowCTR).Delete()
                InitialConn(ALBAdapter)
                ALBAdapter.Update(ds_ALB, "Assure_LivingBenefits")
                RowCount -= 1
            Loop
        Else
            HasError += 1
        End If
        'Transfers Values from the DataGridView to the Database Table in Access
        For RowCTR = 0 To Assure_Benefits.grid_LivingBenefits.Rows.Count - 1
            For ColumnCTR = 0 To Assure_Benefits.grid_LivingBenefits.Columns.Count - 1
                If Assure_Benefits.grid_LivingBenefits.Columns(ColumnCTR).Name = "End of Policy Year" Then
                    PolicyYear = Assure_Benefits.grid_LivingBenefits.Item(ColumnCTR, RowCTR).Value
                ElseIf Assure_Benefits.grid_LivingBenefits.Columns(ColumnCTR).Name = "Guaranteed Cash Value" Then
                    CashValue = Assure_Benefits.grid_LivingBenefits.Item(ColumnCTR, RowCTR).Value
                ElseIf Assure_Benefits.grid_LivingBenefits.Columns(ColumnCTR).Name = "Special Investment Bonus" Then
                    InvestmentBonus = Assure_Benefits.grid_LivingBenefits.Item(ColumnCTR, RowCTR).Value
                ElseIf Assure_Benefits.grid_LivingBenefits.Columns(ColumnCTR).Name = "Accumulated Cash Dividends and Endowments (At 4% Accumulation Rate)" Then
                    Dividends_4 = Assure_Benefits.grid_LivingBenefits.Item(ColumnCTR, RowCTR).Value
                ElseIf Assure_Benefits.grid_LivingBenefits.Columns(ColumnCTR).Name = "Total Living Benefit (At 4% Accumulation Rate)" Then
                    TotalBenefit_4 = Assure_Benefits.grid_LivingBenefits.Item(ColumnCTR, RowCTR).Value
                ElseIf Assure_Benefits.grid_LivingBenefits.Columns(ColumnCTR).Name = "Accumulated Cash Dividends and Endowments (At 8% Accumulation Rate)" Then
                    Dividends_8 = Assure_Benefits.grid_LivingBenefits.Item(ColumnCTR, RowCTR).Value
                ElseIf Assure_Benefits.grid_LivingBenefits.Columns(ColumnCTR).Name = "Total Living Benefit (At 8% Accumulation Rate)" Then
                    TotalBenefit_8 = Assure_Benefits.grid_LivingBenefits.Item(ColumnCTR, RowCTR).Value
                End If
            Next

            dr_ALB = ds_ALB.Tables("Assure_LivingBenefits").NewRow()
            dr_ALB.Item("PolicyYear") = PolicyYear
            dr_ALB.Item("CashValue") = CashValue
            dr_ALB.Item("InvestmentBonus") = InvestmentBonus
            dr_ALB.Item("Dividends_4Percent") = Dividends_4
            dr_ALB.Item("TotalLivingBenefit_4Percent") = TotalBenefit_4
            dr_ALB.Item("Dividends_8Percent") = Dividends_8
            dr_ALB.Item("TotalLivingBenefit_8Percent") = TotalBenefit_8
            ds_ALB.Tables("Assure_Livingenefits").Rows.Add(dr_ALB)

            'ALBAdapter = New OleDbDataAdapter("Select * from Assure_LivingBenefits", LogIn.DBConnection)
            InitialConn(ALBAdapter)
            ALBAdapter.Update(ds_ALB, "Assure_LivingBenefits")
        Next




To summarize, my problems are:
  • My datagridview cell display the errormessage "Insert a Numeric input" even if input is already numeric when database rows are deleted.
  • Problems with adding a new row in the database.

Was This Post Helpful? 0
  • +
  • -

#3 November-06  Icon User is offline

  • D.I.C Regular

Reputation: 46
  • View blog
  • Posts: 407
  • Joined: 04-January 11

Re: Removing ErrrorText in DataGridView Cell. Code was woking before but n

Posted 16 February 2011 - 05:57 AM

I had fixed the problems now. No problem with adding a new row either.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1