如何在打开另一个表单后关闭它

How to close a form after opening another one on top of it

我有以下代码 - 目的是保存订单后,它已被设置为已取消,然后我希望它显示 "New Order" 形式 - 这很好用!

但是,一旦打开新表格,我希望关闭包含已取消订单的原始表格。

  Try
        cmdCheck_Click(sender, New EventArgs)
        cmdTotals_Click(sender, New EventArgs)

        For Each ugr As UltraGridRow In ugProducts.Rows

            If IsDBNull(ugr.Cells("Commission_Value").Value) = True Then
                MsgBox("Unable to save an order where one or more lines has a commission value of 0", MsgBoxStyle.OkOnly, "Error")
                Exit Sub

            Else

                If ugr.Cells("Commission_Value").Value <= 0 Then
                    MsgBox("Unable to save an order where one or more lines has a commission value of 0", MsgBoxStyle.OkOnly, "Error")
                    Exit Sub

                End If
            End If
        Next

        If chCancel.Checked = True Then

            If MsgBox("Are you sure you would like to cancel this order?", MsgBoxStyle.YesNo, "Confirm") = MsgBoxResult.No Then
                Exit Sub
            End If

        End If

        If cmbCustCode.Value = "" Or cmbSupplier.Value = "" Or txtOVal.Text = "" Or txtPVol.Text = "" Or txtPVal.Text = "" Then
            MsgBox("Not enough required data has been entered, cannot save this order", MsgBoxStyle.OkCancel, "Error")
            Exit Sub
        End If

        If isClear = True Then
            Try
                setNewValues()

            Catch ex As Exception
                errorLog(ex)
                MsgBox("Unable to save data, refer to error log", MsgBoxStyle.OkOnly, "Error")
                Exit Sub

            End Try
        End If

        gOrder.Freight = CDec(txtFVal.Text)
        gOrder.AmendedVal = CDec(txtOVal.Text)
        gOrder.AmendedVol = CDec(txtPVol.Text)
        gOrder.externalNotes = rtbExternalNotes.Text
        gOrder.InternalNotes = rtbInternalNotes.Text
        gOrder.OrderCancelled = chCancel.Checked
        gOrder.CommTotal = CDec(txtCVal.Text)
        gOrder.CommVAT = CDec(txtCVat.Text)

        Dim dtLines As New DataTable
        dtLines = ugProducts.DataSource

        Dim dsLines As New DataSet
        dsLines.Tables.Add(dtLines.Copy)

 Select Case gOrder.Stage
Case 4
                Dim proceed As Integer = 0
                For Each ugr As UltraGridRow In ugProducts.Rows

                    If ugr.Cells("Goods_Delivered").Value = False Then
                        If IsDBNull(ugr.Cells("Final_Delivery").Value) = False Then
                            ugr.Cells("Final_Delivery").Value = DBNull.Value
                        End If
                        If isamend = False Then
                            MsgBox("Unable to proceed to next stage until supplier(s) goods have been delivered", MsgBoxStyle.OkOnly, "Goods not delivered")
                        End If
                        proceed = proceed + 1
                    End If

                    If dtFreight Is Nothing Then
                        gOrder.Save(dsLines, , dtfCleared, isClear)
                      If chCancel.Checked = True Then
                            Try
                                Dim f As New frmOrder(con, False, True, currentUser, , admin)
                                f.MdiParent = Me.ParentForm
                                f.Show()

                            Catch ex As Exception
                                errorLog(ex)

                            End Try
                        End If

我试过在Try的开始和结束时都添加Me.Close(),但是,两者都一直给我错误信息

Enumerator has been exhausted. at Infragistics.Shared.SparseArray.CreateItemEnumerator.EnsureNotExhausted() at Infragistics.Shared.SparseArray.CreateItemEnumerator.System.Collections.IEnumerator.MoveNext() at Infragistics.Win.UltraWinGrid.RowEnumerator.MoveNext()

编辑

我认为这是因为保存例程是从另一个子例程调用的。按下的保存按钮调用处理另一个按钮的按钮按下的子程序,这段代码就是那个子程序。

但是,即使将此代码更改为按钮单击中的实际代码(消除间接性),它仍然会发生吗?

那么,如何才能在打开新表单的同时关闭现有表单?另外,请记住,正在打开的表单和现有表单是相同的表单,frmOrder,只是现有表单中包含数据,因此某些方面略有不同。

谢谢

您已经基本解决了您编辑中的问题。

最初可能是 use/open 中同时有太多订阅者。现在无法移动它,因为它仍在 Select Case 中。

如果您将 Me.Close() 移到 Select Case 之外,那么它将正常工作。