Results 1 to 16 of 16

Thread: [RESOLVED] Reset the records of another form

  1. #1

    Thread Starter
    Hyperactive Member nUflAvOrS's Avatar
    Join Date
    Jul 2007
    Location
    Malaysia/ Currently at Singapore
    Posts
    372

    Resolved [RESOLVED] Reset the records of another form

    Hi All,

    I have 2 forms, FormA and FormB
    How to reload the listview of FormA if I fire FormB form_closed event?

    Thanks a million.
    Where there is no hope, there can be no endeavor.

    There are two ways of rising in the world, either by your own industry or by the folly of others.

  2. #2
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: Reset the records of another form

    Is it safe to assume that the code for you ListView is in a public sub or function? If so, then in Form B's FormClosing event or FormClosed, just call the sub or function.

    Let's assume your sub's name is: ListViewSub

    So, unless I'm mistaken, you can do something like this:
    vb Code:
    1. Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
    2.         FormA.ListViewSub()
    3.     End Sub
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  3. #3

    Thread Starter
    Hyperactive Member nUflAvOrS's Avatar
    Join Date
    Jul 2007
    Location
    Malaysia/ Currently at Singapore
    Posts
    372

    Re: Reset the records of another form

    Quote Originally Posted by weirddemon View Post
    Is it safe to assume that the code for you ListView is in a public sub or function? If so, then in Form B's FormClosing event or FormClosed, just call the sub or function.

    Let's assume your sub's name is: ListViewSub

    So, unless I'm mistaken, you can do something like this:
    vb Code:
    1. Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
    2.         FormA.ListViewSub()
    3.     End Sub

    Thanks bro,
    vb Code:
    1. Private Sub frmSREDetails_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
    2.         Dim SREForm As New frmSRE
    3.         SREForm.InitializeListView()
    4.  
    5.     End Sub
    I had used this method before, but the listview still retain old value.
    Where there is no hope, there can be no endeavor.

    There are two ways of rising in the world, either by your own industry or by the folly of others.

  4. #4
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: Reset the records of another form

    In your code, you're declaring the form with a variable, and then calling the Sub. It doesn't retain the value because when the form closes, it disposes of the variable.

    Try just calling the second form with it's actual name:
    vb Code:
    1. Private Sub frmSREDetails_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
    2.         frmSRE.InitializeListView()
    3.  
    4.     End Sub

    If that doesn't work, then I'll probably need to know some more information about how how you want to update your list and with what type of information.
    Last edited by weirddemon; Sep 14th, 2009 at 04:26 AM.
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  5. #5

    Thread Starter
    Hyperactive Member nUflAvOrS's Avatar
    Join Date
    Jul 2007
    Location
    Malaysia/ Currently at Singapore
    Posts
    372

    Re: Reset the records of another form

    Thanks bro,

    By using your method I hit an error.

    reference to a non-shared requires an object references
    Where there is no hope, there can be no endeavor.

    There are two ways of rising in the world, either by your own industry or by the folly of others.

  6. #6
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: Reset the records of another form

    I'm uploading a test project on what I suggested. So hopefully there's no confusion on what I recommended you do. Look at that example, and if that isn't what you're trying to do, then I'll need to know some more information.
    Attached Files Attached Files
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  7. #7

    Thread Starter
    Hyperactive Member nUflAvOrS's Avatar
    Join Date
    Jul 2007
    Location
    Malaysia/ Currently at Singapore
    Posts
    372

    Re: Reset the records of another form

    Your example works fine and perfect but why It could not apply for my application?
    My current project is using vs 2003 instead of vs 2008.
    Where there is no hope, there can be no endeavor.

    There are two ways of rising in the world, either by your own industry or by the folly of others.

  8. #8
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: Reset the records of another form

    Hmm... I'm not entirely sure. I know VS 2003 utilizes an older .NET Framework. However, that shouldn't matter with what you're doing. Could you post the exact code you're using?

    Also, when it does error, does the compiler point to a specific line? If so, which line?
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  9. #9
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,390

    Re: Reset the records of another form

    if formB is loaded from formA use addhandler from where the new form is created to map the formclosed event to a sub that refreshes the list

    Kris

  10. #10

    Thread Starter
    Hyperactive Member nUflAvOrS's Avatar
    Join Date
    Jul 2007
    Location
    Malaysia/ Currently at Singapore
    Posts
    372

    Re: Reset the records of another form

    Quote Originally Posted by weirddemon View Post
    Hmm... I'm not entirely sure. I know VS 2003 utilizes an older .NET Framework. However, that shouldn't matter with what you're doing. Could you post the exact code you're using?

    Also, when it does error, does the compiler point to a specific line? If so, which line?
    Form A

    vb Code:
    1. Private Sub frmSREDetails_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
    2.         Dim SREForm As New frmSRE
    3.         SREForm.InitializeListView()
    4.     End Sub

    Form B Method

    vb Code:
    1. Public Sub InitializeListView()
    2.         ' Set the view to show details.
    3.         With Me.lvwSRE
    4.             .View = View.Details
    5.             .LabelEdit = True
    6.             .AllowColumnReorder = True
    7.             .FullRowSelect = True
    8.             .GridLines = True
    9.             .Sorting = SortOrder.Ascending
    10.             .Columns.Add("PM Order/SRE No", 80, HorizontalAlignment.Left)
    11.             .Columns.Add("Dept", 90, HorizontalAlignment.Left)
    12.             .Columns.Add("CC", 40, HorizontalAlignment.Left)
    13.             .Columns.Add("PO No", 80, HorizontalAlignment.Left)
    14.             .Columns.Add("Date", 68, HorizontalAlignment.Left)
    15.             .Columns.Add("Vendor", 110, HorizontalAlignment.Left)
    16.             .Columns.Add("Type", 60, HorizontalAlignment.Left)
    17.             .Columns.Add("Qty", 40, HorizontalAlignment.Left)
    18.             .Columns.Add("LicenseTag", 60, HorizontalAlignment.Left)
    19.             .Columns.Add("Desc", 150, HorizontalAlignment.Left)
    20.             .Columns.Add("Remarks", 150, HorizontalAlignment.Left)
    21.         End With
    22.  
    23.         LoadList()
    24.  
    25.     End Sub
    26.  
    27.  Private Sub LoadList()
    28.         Dim mydt As New DataTable
    29.         Dim myDS As DataSet
    30.         Dim db As New DBManager
    31.         Dim strDEPT As String
    32.         Dim strVendor As String
    33.         Dim strPurchaseDate As String
    34.         Dim lst As ListView
    35.         Dim lstCount As System.Int16
    36.  
    37.         Try
    38.  
    39.             myDS = db.dbGetSRENewHeader()
    40.             mydt = myDS.Tables("dbGetSRENewHeader")
    41.             If mydt.Rows.Count > 0 Then
    42.                 Me.lvwSRE.Items.Clear()
    43.                 For Each dtrow As DataRow In mydt.Rows
    44.                     lst = Me.lvwSRE
    45.                     lst.Items.Add(dtrow("SRENo"))
    46.                     lst.Tag = lstCount
    47.                     If dtrow("CC").ToString() <> vbNullString Then
    48.                         strDEPT = db.dbGetDeptName(dtrow("CC").ToString())
    49.                     End If
    50.                     lst.Items(lstCount).SubItems.Add(strDEPT.ToString())
    51.                     lst.Items(lstCount).SubItems.Add(dtrow("CC").ToString())
    52.                     lst.Items(lstCount).SubItems.Add(dtrow("POWO").ToString())
    53.                     If dtrow("PurchaseDate").ToString() <> vbNullString Then
    54.                         strPurchaseDate = Format(dtrow("PurchaseDate"), "dd/MM/yyyy").ToString()
    55.                     Else
    56.                         strPurchaseDate = vbNullString
    57.                     End If
    58.                     lst.Items(lstCount).SubItems.Add(strPurchaseDate)
    59.                     If dtrow("VendorID").ToString() <> vbNullString Then
    60.                         strVendor = db.dbGetVendorName(dtrow("VendorID").ToString())
    61.  
    62.                     End If
    63.                     lst.Items(lstCount).SubItems.Add(strVendor)
    64.                     lst.Items(lstCount).SubItems.Add(dtrow("ItemType").ToString())
    65.                     lst.Items(lstCount).SubItems.Add(dtrow("Pqty").ToString())
    66.                     lst.Items(lstCount).SubItems.Add(dtrow("LicenseTag").ToString())
    67.                     lst.Items(lstCount).SubItems.Add(dtrow("Description").ToString())
    68.                     lst.Items(lstCount).SubItems.Add(dtrow("Remarks").ToString())
    69.                     lstCount = lstCount + 1
    70.                 Next
    71.             End If
    72.  
    73.  
    74.             lst = Nothing
    75.         Catch ex As Exception
    76.             MsgBox(ex)
    77.         End Try
    78.     End Sub
    79.  
    80.  Public Function dbGetSRENewHeader() As DataSet
    81.  
    82.         Dim strSQLs As String
    83.         strSQLs = " SELECT SRENo,CC,PurchaseDate,POWO,VendorID,Pqty," & _
    84.                   " Description,LicenseTag,ItemType,Remarks" & _
    85.                   " FROM STS_TRS_SREHeader" & _
    86.                   " WHERE Status = 'N' AND Deleted = 0" & _
    87.                   " ORDER BY SRENo,CC,PurchaseDate"
    88.  
    89.         Return DbConnection.GetRecordSet(strSQLs, Database, "dbGetSRENewHeader", XML)
    90.     End Function
    Where there is no hope, there can be no endeavor.

    There are two ways of rising in the world, either by your own industry or by the folly of others.

  11. #11

    Thread Starter
    Hyperactive Member nUflAvOrS's Avatar
    Join Date
    Jul 2007
    Location
    Malaysia/ Currently at Singapore
    Posts
    372

    Re: Reset the records of another form

    Quote Originally Posted by i00 View Post
    if formB is loaded from formA use addhandler from where the new form is created to map the formclosed event to a sub that refreshes the list

    Kris
    Thanks i00,

    I'm not really understand what you are saying. Hope to explain
    Where there is no hope, there can be no endeavor.

    There are two ways of rising in the world, either by your own industry or by the folly of others.

  12. #12
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: Reset the records of another form

    Change this:
    vb.net Code:
    1. Private Sub frmSREDetails_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
    2.         Dim SREForm As New frmSRE
    3.         SREForm.InitializeListView()
    4.     End Sub

    To this:
    vb.net Code:
    1. Private Sub frmSREDetails_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
    2.         frmSRE.InitializeListView()
    3.     End Sub

    That should work. It's what I said from the beginning. I only tested it with the InitializeListView sub. I wasn't able to test it with the other because I don't have access to your db.

    It should still work though.
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  13. #13

    Thread Starter
    Hyperactive Member nUflAvOrS's Avatar
    Join Date
    Jul 2007
    Location
    Malaysia/ Currently at Singapore
    Posts
    372

    Re: Reset the records of another form

    Quote Originally Posted by weirddemon View Post
    Change this:
    vb.net Code:
    1. Private Sub frmSREDetails_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
    2.         Dim SREForm As New frmSRE
    3.         SREForm.InitializeListView()
    4.     End Sub

    To this:
    vb.net Code:
    1. Private Sub frmSREDetails_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
    2.         frmSRE.InitializeListView()
    3.     End Sub

    That should work. It's what I said from the beginning. I only tested it with the InitializeListView sub. I wasn't able to test it with the other because I don't have access to your db.

    It should still work though.
    Thanks bro,

    I had tested this method and revert the output at thread #5.
    I would hit the error (reference to a non-shared requires an object references ) if I didn't declared object.

    FYI : I open form B by using showdialog() instead of .show()
    Where there is no hope, there can be no endeavor.

    There are two ways of rising in the world, either by your own industry or by the folly of others.

  14. #14
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,390

    Re: Reset the records of another form

    I meant when you open your form do something like this eg in in a button click:

    vb Code:
    1. Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button.Click
    2.         Dim x As New frmYours
    3.         AddHandler x.FormClosed, AddressOf frmYours_FormClosed
    4.         x.Show()
    5. End Sub

    and have another sub within the calling form that looks something like this:

    vb Code:
    1. Private Sub frmYours_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs)
    2.  
    3.         RefreshList()
    4. End Sub

  15. #15
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,390

    Re: Reset the records of another form

    Just realized u said u use show dialogue ... if this is the case you can use something like this:

    vb Code:
    1. Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button.Click
    2.         Dim x As New frmYours
    3.         x.ShowDialogue()
    4.         RefreshList()
    5. End Sub

  16. #16

    Thread Starter
    Hyperactive Member nUflAvOrS's Avatar
    Join Date
    Jul 2007
    Location
    Malaysia/ Currently at Singapore
    Posts
    372

    Re: Reset the records of another form

    Quote Originally Posted by i00 View Post
    Just realized u said u use show dialogue ... if this is the case you can use something like this:

    vb Code:
    1. Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button.Click
    2.         Dim x As New frmYours
    3.         x.ShowDialogue()
    4.         RefreshList()
    5. End Sub

    Thanks i00,

    I have resolved the problem by using your method.

    Thanks a million and also thanks to weirddemon
    Where there is no hope, there can be no endeavor.

    There are two ways of rising in the world, either by your own industry or by the folly of others.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width