Reputation: 1
Edited 3/23 to include suggested changes and new information.
I have a vb.net Windows form, rptBase, with a statusstrip and a ToolStripStatusLabel tssl1. Two forms, rpt1 and rpt2, inherit rptBase.
On frmMain I have ListBox1 with:
Private Sub ListBox1_Click(sender As Object, e As EventArgs) Handles ListBox1.Click
Dim frmRpt As New frmRptBase
Select Case ListBox1.SelectedIndex
Case 1
frmRpt = New frmRpt1()
frmRpt.Text = "Report 1"
frmRpt.Show()
Case 2
frmRpt = New frmRpt2()
frmRpt.Text = "Report 2"
frmRpt.Show()
End Select
AddForm(frmRpt)
End Sub
I would like to report the progress of the reports but when I update tssl1.text on report 1 it also updates report 2 and vice versa. How do I update just one or the other?
I have a dictionary and a method to save a reference to the forms
Public Sub AddForm(frm As Object)
m_dctFrms.Add(frm, Str(frm.FormID))
End Sub
and a method to update the statusbar
Public Sub UpdateStatus(strMsg As String)
tssl1.Text = strMsg
End Sub
I run the program, open report 1, then open report 2, then run report1.
New information:
The report runs in a background worker. When I call UpdateStatus from the DoWork sub, it works as expected. When I call UpdateStatus from the ProgressChanged sub, it does not.
Private Sub bw_DoWork(sender As Object, e As DoWorkEventArgs) Handles bw.DoWork
UpdateStatus("This works, only one form updated.")
End Sub
Private Sub bw_ProgressChanged(sender As Object, e As ProgressChangedEventArgs) Handles bw.ProgressChanged
UpdateStstus("This does not work. Both form are updated.")
End Sub
Upvotes: 0
Views: 47
Reputation: 927
maybe a simple form array (+ simplifie a bit your code) :
Dim arrForm(5) As Form 'set max forms count
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
If IsNothing(arrForm(ListBox1.SelectedIndex)) Then
Dim frmRpt As New frmRptBase
frmRpt.Text = "Report " & ListBox2.SelectedIndex
arrForm(ListBox1.SelectedIndex) = frmRpt
frmRpt.Show()
End If
End Sub
Public Sub UpdateStatus(intKey As Integer, strMsg As String)
Dim frm As frmRptBase = arrForm(intKey)
frm.tssl1.Text = strMsg
End Sub
Upvotes: 0