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.
Printable View
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.
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:
Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing FormA.ListViewSub() End Sub
Thanks bro,
I had used this method before, but the listview still retain old value.vb Code:
Private Sub frmSREDetails_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing Dim SREForm As New frmSRE SREForm.InitializeListView() End Sub
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:
Private Sub frmSREDetails_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing frmSRE.InitializeListView() 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.
Thanks bro,
By using your method I hit an error.
reference to a non-shared requires an object references
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.
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.
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?
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
Form A
vb Code:
Private Sub frmSREDetails_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing Dim SREForm As New frmSRE SREForm.InitializeListView() End Sub
Form B Method
vb Code:
Public Sub InitializeListView() ' Set the view to show details. With Me.lvwSRE .View = View.Details .LabelEdit = True .AllowColumnReorder = True .FullRowSelect = True .GridLines = True .Sorting = SortOrder.Ascending .Columns.Add("PM Order/SRE No", 80, HorizontalAlignment.Left) .Columns.Add("Dept", 90, HorizontalAlignment.Left) .Columns.Add("CC", 40, HorizontalAlignment.Left) .Columns.Add("PO No", 80, HorizontalAlignment.Left) .Columns.Add("Date", 68, HorizontalAlignment.Left) .Columns.Add("Vendor", 110, HorizontalAlignment.Left) .Columns.Add("Type", 60, HorizontalAlignment.Left) .Columns.Add("Qty", 40, HorizontalAlignment.Left) .Columns.Add("LicenseTag", 60, HorizontalAlignment.Left) .Columns.Add("Desc", 150, HorizontalAlignment.Left) .Columns.Add("Remarks", 150, HorizontalAlignment.Left) End With LoadList() End Sub Private Sub LoadList() Dim mydt As New DataTable Dim myDS As DataSet Dim db As New DBManager Dim strDEPT As String Dim strVendor As String Dim strPurchaseDate As String Dim lst As ListView Dim lstCount As System.Int16 Try myDS = db.dbGetSRENewHeader() mydt = myDS.Tables("dbGetSRENewHeader") If mydt.Rows.Count > 0 Then Me.lvwSRE.Items.Clear() For Each dtrow As DataRow In mydt.Rows lst = Me.lvwSRE lst.Items.Add(dtrow("SRENo")) lst.Tag = lstCount If dtrow("CC").ToString() <> vbNullString Then strDEPT = db.dbGetDeptName(dtrow("CC").ToString()) End If lst.Items(lstCount).SubItems.Add(strDEPT.ToString()) lst.Items(lstCount).SubItems.Add(dtrow("CC").ToString()) lst.Items(lstCount).SubItems.Add(dtrow("POWO").ToString()) If dtrow("PurchaseDate").ToString() <> vbNullString Then strPurchaseDate = Format(dtrow("PurchaseDate"), "dd/MM/yyyy").ToString() Else strPurchaseDate = vbNullString End If lst.Items(lstCount).SubItems.Add(strPurchaseDate) If dtrow("VendorID").ToString() <> vbNullString Then strVendor = db.dbGetVendorName(dtrow("VendorID").ToString()) End If lst.Items(lstCount).SubItems.Add(strVendor) lst.Items(lstCount).SubItems.Add(dtrow("ItemType").ToString()) lst.Items(lstCount).SubItems.Add(dtrow("Pqty").ToString()) lst.Items(lstCount).SubItems.Add(dtrow("LicenseTag").ToString()) lst.Items(lstCount).SubItems.Add(dtrow("Description").ToString()) lst.Items(lstCount).SubItems.Add(dtrow("Remarks").ToString()) lstCount = lstCount + 1 Next End If lst = Nothing Catch ex As Exception MsgBox(ex) End Try End Sub Public Function dbGetSRENewHeader() As DataSet Dim strSQLs As String strSQLs = " SELECT SRENo,CC,PurchaseDate,POWO,VendorID,Pqty," & _ " Description,LicenseTag,ItemType,Remarks" & _ " FROM STS_TRS_SREHeader" & _ " WHERE Status = 'N' AND Deleted = 0" & _ " ORDER BY SRENo,CC,PurchaseDate" Return DbConnection.GetRecordSet(strSQLs, Database, "dbGetSRENewHeader", XML) End Function
Change this:vb.net Code:
Private Sub frmSREDetails_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing Dim SREForm As New frmSRE SREForm.InitializeListView() End Sub
To this:vb.net Code:
Private Sub frmSREDetails_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing frmSRE.InitializeListView() 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.
I meant when you open your form do something like this eg in in a button click:
vb Code:
Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button.Click Dim x As New frmYours AddHandler x.FormClosed, AddressOf frmYours_FormClosed x.Show() End Sub
and have another sub within the calling form that looks something like this:
vb Code:
Private Sub frmYours_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) RefreshList() End Sub
Just realized u said u use show dialogue ... if this is the case you can use something like this:
vb Code:
Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button.Click Dim x As New frmYours x.ShowDialogue() RefreshList() End Sub