Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagridview refresh problem

Status
Not open for further replies.

Appollo14

Technical User
Sep 4, 2003
182
0
0
GB
Hi Guys,

I've been playing around with this for hours and seem to be getting nowhere fast!

I have 2 forms (both with datagridviews). User clicks on form one and gets form two containing details for the row they clicked on and the ability to edit those details. When the user makes changes in the details form and closes it i want the main form to reflect those changes.

I have placed this code on the details form;


Private Sub BtnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
If MessageBox.Show("Are you sure you want to close?", "Stop entering order?", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
dlgOrd.OrdersGridReload()
Me.Close()
End If


hoping that it will run this code (which is a sub on the main form);


Public Sub OrdersGridReload()
Me.Sp_PFillOrderGridTableAdapter.Fill(Me.DsOrders.sp_PFillOrderGrid)
DGVOrders.Width = Me.Width
DGVOrders.Height = (Me.Height / 100) * 85
Me.dwOrdNum.Width = Screen.PrimaryScreen.WorkingArea.Width / 100 * 7.5
Me.szAccCode.Width = Screen.PrimaryScreen.WorkingArea.Width / 100 * 7.5
Me.szName.Width = Screen.PrimaryScreen.WorkingArea.Width / 100 * 14
Me.dtOrdDate.Width = Screen.PrimaryScreen.WorkingArea.Width / 100 * 7.5
Me.szAuthBy.Width = Screen.PrimaryScreen.WorkingArea.Width / 100 * 10
Me.szStatus.Width = Screen.PrimaryScreen.WorkingArea.Width / 100 * 7.5
Me.szNotes.Width = Screen.PrimaryScreen.WorkingArea.Width / 100 * 22
Me.dwrValue.Width = Screen.PrimaryScreen.WorkingArea.Width / 100 * 6
Me.DtCompDate.Width = Screen.PrimaryScreen.WorkingArea.Width / 100 * 8.5
Me.DGVOrders.RowHeadersWidth = Screen.PrimaryScreen.WorkingArea.Width / 100 * 2.5
Dim i As Integer
Dim r As DataGridViewRow
i = 0
For Each r In Me.DGVOrders.Rows
Me.DGVOrders.Rows(i).DefaultCellStyle.BackColor = Color.FromArgb(Me.DGVOrders.Rows(i).Cells("dwColourRef").Value)
i = i + 1
Next
Me.DGVOrders.Refresh()
End Sub

Stepping thro the code it all appears to work as required, however the screen is not updated.

Strangely, adding a button to the main form with the following code works!


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
OrdersGridReload()
End Sub

Can anyone tell me whats going on or where i'm going wrong?

Thanks,
Noel.
 
I'm not sure but add this to the button command.

Code:
dlgOrd.Show

before the Me.Close

It probably isn't refreshing the "new" copy yet.

Try it! :)
Brett
 
Hi Brett,

Thanks for the suggestion.

i gave it a go and what i got was another instance of the main form - which is displaying the refreshed data - sitting over the original form which is still displaying the old value.

Regards,
Noel.
 
Before you go to the new form, do a me.close/me.hide. Sounds like that should fix your problem.
Brett
 
Hi Brett,

Thanks for taking the time to respond again. Perhaps I should have stated that this is an MDI app and I want the mainform to be always on display.

Just to give you an outline of the project.

User logs into system and is presented with frmPopMain which is the MDI parent. This form contains a readonly datagridview which contains header information regarding Purchase Orders. On right clicking a row the user is presented with frmOrderEntry which gives full details of the order selected. The user can then change the deatils of the order and then closes the form. When the form closes the user returns to the frmPopMain to see the other orders in progress.

Sorry for not making it very clear.

Regards,
Noel.
 
Ok. One last suggestion before I logoff. Try...

Code:
If MessageBox.Show("Are you sure you want to close?", "Stop entering order?", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
            [b]dlgOrd.Hide[/b]
            dlgOrd.OrdersGridReload()
            [b]dlgOrd.Show[/b]
            Me.Close()
        End If

Sorry I couldn't help you more!
Brett
 
Hi Brett,

due to a severe case of man flu I logged of before you last night and have only just managed to try this solution.

Unfortunately this method still created a new instance of the main form and did not refresh the existing main form.

Please dont apologise for your efforts, i've been banging my head against this one for days now and am glad to try any new suggests that you or anybody can come up with.

Thanks again,
Noel.
 
Ok. One last ditch try...
Try:

dlgOrd.Close

instead of

dlgOrd.Hide


and do the show as usual...


After that I think I'm stumped as well. If you get the solution, please post it.

Thanks!
Brett
 
Hi Brett,

can we put this one down to experience (or stupidity if you wish!!). From the methods you suggested I worked out that instead of working on the current main form i'd actually created a NEW instance of the form, so a couple of tweaks to the code that opened the order details form ie instead of this;

Private Sub DGVOrders_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DGVOrders.MouseDown
If e.Button = Windows.Forms.MouseButtons.Right Then
OEdlg = New frmOrderEntry
OEdlg.NewRec = 0
OEdlg.strUser = strUser
OEdlg.UserId = UserId
OEdlg.OrderId = DGVOrders.CurrentRow.Cells.Item(0).Value
OEdlg.AccID = DGVOrders.CurrentRow.Cells.Item(2).Value
OEdlg.ShowDialog()
End If
End Sub

I've changed the code to read;

Private Sub DGVOrders_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DGVOrders.MouseDown
If e.Button = Windows.Forms.MouseButtons.Right Then
POPMain = Me
OEdlg = New frmOrderEntry
OEdlg.dlgOrd = Me
OEdlg.NewRec = 0
OEdlg.strUser = strUser
OEdlg.UserId = UserId
OEdlg.OrderId = DGVOrders.CurrentRow.Cells.Item(0).Value
OEdlg.AccID = DGVOrders.CurrentRow.Cells.Item(2).Value
OEdlg.ShowDialog()
End If
End Sub

and everything is working as i wanted.

Thanks for the help, i'm not sure i would've spotted it without your help.

Regards,
Noel.
 
Glad I could help. I was kind of steering you in that direction, even though I don't think I realized it until now. LOL! Glad you got it. I know how frustrating data grids can be!
Take care,
Brett
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top