Click here to Skip to main content
15,885,952 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a MDI form which opens a docked child form (user dashboard) that is not closable by the users. The MDI can then open up either docked child forms within the MDI or non docked child forms.

The problem I am running into is that if the user opens a customer info docked form and they hit save on that form, after the save it switches to the dashboard form automatically.

on load and loading the dashboard


VB
'Display Main Dashboard in MDI
            Dim fc As FormCollection = Application.OpenForms
            Dim FormFound As Boolean = False
            For Each frm As Form In fc
                If frm.Name = "frmDashboard" Then
                    frm.Focus()
                    FormFound = True
                End If
            Next

            If FormFound = False Then
                Dim frm As New frmDashboard
                With frm
                    .MdiParent = Me
                    '.Dock = DockStyle.Fill
                    .FormBorderStyle = FormBorderStyle.Fixed3D
                    .WindowState = FormWindowState.Maximized
                    .Show()
                    _log.Info("Opening the dashboard form")
                End With
            End If


If user calls the customer form

VB
Private Sub tsbCustVend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbCustVend.Click
        Try
            tvNavigation.Enabled = False
            Me.Cursor = Cursors.WaitCursor

            Dim fc As FormCollection = Application.OpenForms
            Dim FormFound As Boolean = False
            For Each frm As Form In fc
                If frm.Name = "frmCustomer" Then
                    frm.Focus()
                    FormFound = True
                End If
            Next

            If FormFound = False Then
                Dim CustForm As New frmCustomer
                _log.Info("Opening form " & CustForm.Name)
                With CustForm
                    .MdiParent = Me
                    '.Dock = DockStyle.Fill
                    .FormBorderStyle = FormBorderStyle.Sizable
                    .WindowState = FormWindowState.Maximized
                End With
                CustForm.Show()
            End If

        Catch ex As Exception
            _log.Error(ex.ToString & vbCrLf & ex.StackTrace.ToString)
            MessageBox.Show(ex.ToString, "", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            Me.Invalidate()
            tvNavigation.Enabled = True
            Me.Cursor = Cursors.Default

        End Try

    End Sub


After the user save a new or existing customer the background dashboard form is brought the the front and focused.

Any help is appreciated Thanks


What I have tried:

The code above is what I have and not sure how to prevent on save of the child form to not switch back to the previous form.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900