0

我有一个 MDI Parent 作为父窗体,我用它来打开和组织其他窗体作为其中的子窗体。我使用这种方法打开子表单:

Public Sub OpenForm(ByVal frm As Form)
    frm.MdiParent = MainView
    frm.Show()
End Sub

该方法可以正常工作,使用它打开子表单我没有任何问题。我在每个子表单中有 3 个项目:

1- DataGridViewX(来自 DevComponents.DotNetBar.Controls)

2- 面板

3-用户控制

我可以正确使用这些项目中的每一个,并且没有出现错误。DataGridViewX 与 DataSource 连接,一切正常。当我在 MDI Parent 中打开 2 个或更多表单然后尝试关闭它们时,就会出现问题。错误是:

    The following exception occurred in the DataGridView:
System.IndexOutOfRangeException: Index 0 does not have a value.
at
System.Windows.Forms.CurrencyManager.get_Item(Int32index) 
at
System.Windows.Forms.DataGridView.DataGridViewDataConnection.G" and caption "DataGridView Default Error Dialog".

这是负责错误的代码:

Partial Class Form1
    Inherits DevComponents.DotNetBar.OfficeForm

    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()>
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing) '' <<<< ERROR LINE
        End Try
    End Sub

现在显然我没有在设计器内部编写代码,也没有使用代码将元素放入表单中。我使用设计器界面。

我应该怎么办 ?谢谢

4

1 回答 1

0

只需将 DataGridViewX 的绑定源设置为空,问题就解决了!

Private Sub theForm_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
    DataGridViewX1.DataSource = Nothing
End Sub
于 2016-08-03T06:33:22.197 回答