Hagita
asked on
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(d tRow, 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("tb lConstruct ion")) Then dtsCR.Tables("tblConstruct ion").Clea r()
If objBs.GetTable(dtsCR, "tblConstruction", "SELECT * FROM tblConstruction WHERE LabRepId=" & _
lngLabRepId & " ORDER BY COUNTER ASC") Then
DTV = dtsCR.Tables("tblConstruct ion").Defa ultView
dtgCon.DataSource = DTV
DrawGrid()
End If
========================== ========== ========== ========== =======
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(d
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("tb
If objBs.GetTable(dtsCR, "tblConstruction", "SELECT * FROM tblConstruction WHERE LabRepId=" & _
lngLabRepId & " ORDER BY COUNTER ASC") Then
DTV = dtsCR.Tables("tblConstruct
dtgCon.DataSource = DTV
DrawGrid()
End If
==========================
ASKER
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
You mean if you add a thread.sleep between update and reload, it works?
ASKER
I changed the Messagbox "UPDATED" timing to be before the refresh code and now it works...
Can you show the code you have now?
ASKER
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(d tRow, 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.Canc elEventArg s
txtRepNo_Validating(Me.btn Save, e)
End If
End If
======================
Private Sub txtRepNo_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.Canc elEventArg s) 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.Check ed = False
RougnessCheckBox.Checked = False
VoidsCheckBox.Checked = False
dtTestdate.Value = dtDate
NEW_ROW = True
If Not IsNothing(dtsCR.Tables("tb lConstruct ion")) Then dtsCR.Tables("tblConstruct ion").Clea r()
If objBs.GetTable(dtsCR, "tblConstruction", "SELECT * FROM tblConstruction WHERE LabRepId=" & _
lngLabRepId & " ORDER BY COUNTER ASC") Then
DTV = dtsCR.Tables("tblConstruct ion").Defa ultView
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.Co unt > 0 Then
lngLabRepId = CLng(dtsCR.Tables("CS").Ro ws(0)("Lab RepID"))
If lngLabRepId > 0 Then
NEW_ROW = False
Else
NEW_ROW = True
End If
txtRepNo.Text = dtsCR.Tables("CS").Rows(0) ("LabRepID ").ToStrin g
txtEltekPN.Text = dtsCR.Tables("CS").Rows(0) ("EltekPN" ).ToString
cmbLotNo.Text = dtsCR.Tables("CS").Rows(0) ("WorkingN O").ToStri ng
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.Check ed = dtsCR.Tables("CS").Rows(0) ("Registra tion")
RougnessCheckBox.Checked = dtsCR.Tables("CS").Rows(0) ("Rougness ")
VoidsCheckBox.Checked = dtsCR.Tables("CS").Rows(0) ("Voids")
dtTestdate.Value = CDate(dtsCR.Tables("CS").R ows(0)("da tee"))
txtTester.Text = dtsCR.Tables("CS").Rows(0) ("TesterNa me").ToStr ing
End If
End If
If Not IsNothing(dtsCR.Tables("tb lConstruct ion")) Then dtsCR.Tables("tblConstruct ion").Clea r()
If objBs.GetTable(dtsCR, "tblConstruction", "SELECT * FROM tblConstruction WHERE LabRepId=" & _
lngLabRepId & " ORDER BY COUNTER ASC") Then
DTV = dtsCR.Tables("tblConstruct ion").Defa ultView
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
If objBs.UpdateCrossSection(d
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.Canc
txtRepNo_Validating(Me.btn
End If
End If
======================
Private Sub txtRepNo_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.Canc
Try
If txtRepNo.Text <> "" Then
lngLabRepId = CLng(txtRepNo.Text)
If IsNewLabRepId(lngLabRepId)
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.Check
RougnessCheckBox.Checked = False
VoidsCheckBox.Checked = False
dtTestdate.Value = dtDate
NEW_ROW = True
If Not IsNothing(dtsCR.Tables("tb
If objBs.GetTable(dtsCR, "tblConstruction", "SELECT * FROM tblConstruction WHERE LabRepId=" & _
lngLabRepId & " ORDER BY COUNTER ASC") Then
DTV = dtsCR.Tables("tblConstruct
dtgCon.DataSource = DTV
DrawGrid()
End If
Else
Me.Text = "Update Row - Cross Section Report"
If Not IsNothing(dtsCR.Tables("CS
If objBs.GetCs(dtsCR, lngLabRepId) Then
If dtsCR.Tables("CS").Rows.Co
lngLabRepId = CLng(dtsCR.Tables("CS").Ro
If lngLabRepId > 0 Then
NEW_ROW = False
Else
NEW_ROW = True
End If
txtRepNo.Text = dtsCR.Tables("CS").Rows(0)
txtEltekPN.Text = dtsCR.Tables("CS").Rows(0)
cmbLotNo.Text = dtsCR.Tables("CS").Rows(0)
CuDepoTextBox.Text = dtsCR.Tables("CS").Rows(0)
txtNote.Text = dtsCR.Tables("CS").Rows(0)
CracksCheckBox.Checked = dtsCR.Tables("CS").Rows(0)
RegistrationCheckBox.Check
RougnessCheckBox.Checked = dtsCR.Tables("CS").Rows(0)
VoidsCheckBox.Checked = dtsCR.Tables("CS").Rows(0)
dtTestdate.Value = CDate(dtsCR.Tables("CS").R
txtTester.Text = dtsCR.Tables("CS").Rows(0)
End If
End If
If Not IsNothing(dtsCR.Tables("tb
If objBs.GetTable(dtsCR, "tblConstruction", "SELECT * FROM tblConstruction WHERE LabRepId=" & _
lngLabRepId & " ORDER BY COUNTER ASC") Then
DTV = dtsCR.Tables("tblConstruct
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yes. You are right. its more elegant and it works.Thanks!
Glad to help :-)
If objBs.UpdateTable(DT, "frmCrossSection") Then
is returning true? Step through the code to see what's going on.