Wrox Programmer Forums
|
Visual Basic 2008 Professionals For advanced Visual Basic coders working in version 2008. Beginning-level questions will be redirected to other forums,
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2008 Professionals section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 12th, 2010, 04:31 PM
Registered User
 
Join Date: Feb 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Datagrid refresh

Hello

I have been looking around for some sample code that is eluding me.

I have a small vb.net app that allows a user to select a row in a datagrid control that launches a detail form. When I then update or change the record on the detail form and save, how do I refresh the datagrid on the master form?

I was told I need to write an event handler but I am not sure how. Here is what I wrote so far.

The form with the datagrid is called CustomerList
The detail form is called CustomerDetail

Here is the relevant code on the CustomerList form
Code:
'in the class header
Dim WithEvents cdetail As New CustomerDetail

'sub written to open customerdetail
Private Sub OpenCustomer()

        Try
            Dim rowview As Data.DataRowView
            Dim selectedrow As DS.CustomerRow

            rowview = CType(CustomerBindingSource.Current, DataRowView)
            selectedrow = CType(rowview.Row, DS.CustomerRow)

            cdetail.CustomerLoad(selectedrow.CustomerID)

            If Not IsNothing(cdetail) Then
                If Not cdetail.IsDisposed Then
                    cdetail.BringToFront()
                    cdetail.Show()
                Else
                    cdetail = New CustomerDetail
                    cdetail.Show()
                End If
            Else
                cdetail = New CustomerDetail
                cdetail.Show()
            End If

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    End Sub

'calls the event handler to refill the dataset
Private Sub cdetail_DataHasChanged() Handles cdetail.DataHasChanged
        Try
            Me.CustomerTableAdapter.Fill(Me.DS.Customer)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
Here is the code on the CustomerDetail side

Code:
'class header
Event DataHasChanged()

'custom load routine
Friend Sub CustomerLoad(ByVal CustomerID As Long)
        Try
            Me.CustomerTableAdapter.FillByCustomerID(DS.Customer, CustomerID)
        Catch ex As Exception

        End Try

    End Sub


    Private Sub CustomerBindingSource_ListChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ListChangedEventArgs) Handles CustomerBindingSource.ListChanged
        RaiseEvent DataHasChanged()
End Sub

I hope that is not confusing. I can break the code up further if it helps

Ryan





Similar Threads
Thread Thread Starter Forum Replies Last Post
Datagrid won't refresh cole C# 2005 0 April 27th, 2007 10:44 AM
How to refresh the datagrid? Byock ASP.NET 1.0 and 1.1 Basics 2 December 11th, 2006 05:51 AM
Refresh DataGrid without PostBack Baby_programmer Classic ASP XML 1 April 2nd, 2005 04:22 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.