Data Grid View Refresh Problem after Update Table

Hello Experts, need a big and fast help here Please...
I use a datagridview in a vb.net project to show data from a disconnected dataset. when the user update the grid data I use this code to update table and refresh the grid's data. problem is the data wont refresh even though the update table has been done:
======================================================
  If objBs.UpdateCrossSection(dtRow, NEW_ROW) Then
                NEW_ROW = False
                EDIT_MODE = False
                dtgCon.Update()
                'DTV = dtgCon.DataSource
                DT = DTV.Table
                If objBs.UpdateTable(DT, "frmCrossSection") Then

                    dtgCon.DataSource = Nothing
                    If Not IsNothing(DTV) Then DTV = Nothing
                    If Not IsNothing(dtsCR.Tables("tblConstruction")) Then dtsCR.Tables("tblConstruction").Clear()
                    If objBs.GetTable(dtsCR, "tblConstruction", "SELECT * FROM tblConstruction WHERE LabRepId=" & _
                          lngLabRepId & " ORDER BY COUNTER ASC") Then
                        DTV = dtsCR.Tables("tblConstruction").DefaultView
                        dtgCon.DataSource = DTV
                        DrawGrid()
                    End If
===============================================================
HagitaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CodeCruiserCommented:
And you are sure that the DB is being updated? And you are sure that

 If objBs.UpdateTable(DT, "frmCrossSection") Then


is returning true? Step through the code to see what's going on.
0
HagitaAuthor Commented:
Yes I know that it is updated. I solved it by timing and waiting few seconds : it refreshes well now. still dont understand why it happens
0
CodeCruiserCommented:
You mean if you add a thread.sleep between update and reload, it works?
0
CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

HagitaAuthor Commented:
I changed the Messagbox "UPDATED" timing to be before the refresh code and now it works...
0
CodeCruiserCommented:
Can you show the code you have now?
0
HagitaAuthor Commented:
Sure I can. also notice I call the txtRepNo_Validating sub to do the refresh but its the same code I used earlier. the MsgBox changes everything:

     If objBs.UpdateCrossSection(dtRow, NEW_ROW) Then
                NEW_ROW = False
                EDIT_MODE = False
                dtgCon.Update()
                DTV = dtgCon.DataSource
                DT = DTV.Table
                If objBs.UpdateTable(DT, "frmCrossSection") Then
                    MsgBox("Update Success", vbInformation)
                    Dim e As System.ComponentModel.CancelEventArgs
                    txtRepNo_Validating(Me.btnSave, e)
                End If
            End If
======================
 Private Sub txtRepNo_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtRepNo.Validating
        Try
            If txtRepNo.Text <> "" Then
                lngLabRepId = CLng(txtRepNo.Text)
                If IsNewLabRepId(lngLabRepId) Then 'Is New Row
                    Me.Text = "Add New Row - Cross Section Report"
                    Dim dtDate As Date
                    dtDate = Today & " " & TimeOfDay
                    txtEltekPN.Text = ""
                    cmbLotNo.Text = ""
                    CuDepoTextBox.Text = ""
                    txtNote.Text = ""
                    CracksCheckBox.Checked = False
                    RegistrationCheckBox.Checked = False
                    RougnessCheckBox.Checked = False
                    VoidsCheckBox.Checked = False
                    dtTestdate.Value = dtDate

                    NEW_ROW = True
                    If Not IsNothing(dtsCR.Tables("tblConstruction")) Then dtsCR.Tables("tblConstruction").Clear()
                    If objBs.GetTable(dtsCR, "tblConstruction", "SELECT * FROM tblConstruction WHERE LabRepId=" & _
                             lngLabRepId & " ORDER BY COUNTER ASC") Then
                        DTV = dtsCR.Tables("tblConstruction").DefaultView
                        dtgCon.DataSource = DTV
                        DrawGrid()
                    End If
                              Else
                    Me.Text = "Update Row - Cross Section Report"
                    If Not IsNothing(dtsCR.Tables("CS")) Then dtsCR.Tables("CS").Clear()
                    If objBs.GetCs(dtsCR, lngLabRepId) Then
                        If dtsCR.Tables("CS").Rows.Count > 0 Then
                            lngLabRepId = CLng(dtsCR.Tables("CS").Rows(0)("LabRepID"))
                            If lngLabRepId > 0 Then
                                NEW_ROW = False
                            Else
                                NEW_ROW = True
                            End If
                            txtRepNo.Text = dtsCR.Tables("CS").Rows(0)("LabRepID").ToString
                            txtEltekPN.Text = dtsCR.Tables("CS").Rows(0)("EltekPN").ToString
                            cmbLotNo.Text = dtsCR.Tables("CS").Rows(0)("WorkingNO").ToString
                            CuDepoTextBox.Text = dtsCR.Tables("CS").Rows(0)("CuDepo").ToString
                            txtNote.Text = dtsCR.Tables("CS").Rows(0)("Notes").ToString
                            CracksCheckBox.Checked = dtsCR.Tables("CS").Rows(0)("Cracks")
                            RegistrationCheckBox.Checked = dtsCR.Tables("CS").Rows(0)("Registration")
                            RougnessCheckBox.Checked = dtsCR.Tables("CS").Rows(0)("Rougness")
                            VoidsCheckBox.Checked = dtsCR.Tables("CS").Rows(0)("Voids")
                            dtTestdate.Value = CDate(dtsCR.Tables("CS").Rows(0)("datee"))
                            txtTester.Text = dtsCR.Tables("CS").Rows(0)("TesterName").ToString
                        End If
                    End If
                    If Not IsNothing(dtsCR.Tables("tblConstruction")) Then dtsCR.Tables("tblConstruction").Clear()
                    If objBs.GetTable(dtsCR, "tblConstruction", "SELECT * FROM tblConstruction WHERE LabRepId=" & _
                             lngLabRepId & " ORDER BY COUNTER ASC") Then
                        DTV = dtsCR.Tables("tblConstruction").DefaultView
                        dtgCon.DataSource = DTV
                        DrawGrid()
                    End If
                          End If
            End If
        Catch ex As Exception
            MessageBox.Show("Error occured: " & ex.Message, "Error.", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub
0
CodeCruiserCommented:
I think Thread.Sleep will achieve the same thing. Give that a try as well

System.Threading.Thread.Sleep(500)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
HagitaAuthor Commented:
Yes. You are right. its more elegant and it works.Thanks!
0
CodeCruiserCommented:
Glad to help :-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.