在运行时清空ControlCollection

时间:2012-03-29 20:41:33

标签: vb.net controlcollection

我无法在任何地方找到答案。我定义了一个表单控件集合的新实例,但在运行时,该集合是空的。它适用于表单上的一个加载按钮,但不适用于另一个加载按钮。代码完全相同,但一个有效,另一个没有。以下是相关代码:

Private Sub miFLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles miFLoad.Click
    Dim FilePath As String = "C:\FList\FList.flt"
    Dim LoadFile As New SaveandLoad.SaveAndLoad
    Dim FileRead As New Simple3Des("MyPassword")
    Dim FileString As String = FileRead.ReadFile(FilePath)


    With LoadFile
        .WhichList = dgFList
        .FilePath = FilePath
        .DecryptedString = FileRead.DecryptData(FileString)
    End With

    Call LoadFile.LoadFile()
End Sub

此加载按钮未加载

Private Sub miCLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles miCLoad.Click
    Dim FilePath As String = "C:\FList\CList.clt"
    Dim LoadFile As New SaveandLoad.SaveAndLoad
    Dim FileRead As New Simple3Des("MyPassword")
    Dim FileString As String = FileRead.ReadFile(FilePath)


    With LoadFile
        .WhichList = dgCourses
        .FilePath = FilePath
        .DecryptedString = FileRead.DecryptData(FileString)
    End With

    Call LoadFile.LoadFile()
End Sub

这是。

Public Sub LoadFile()

        Dim dgRow As DataGridViewRow
        Dim dgCell As DataGridViewTextBoxCell
        Dim Lines() As String = DecryptedString.Split(vbLf)
        Dim LinesList As List(Of String) = Lines.ToList
        LinesList.RemoveAt(Lines.Length - 1)

        For Each Line As String In LinesList
            Dim Fields() As String = Line.Split(",")
            dgRow = New DataGridViewRow
            For x = 0 To (WhichList.Columns.Count - 1) Step 1
                dgCell = New DataGridViewTextBoxCell
                dgCell.Value = Fields(x).ToString
                dgRow.Cells.Add(dgCell)
            Next
            WhichList.Rows.Add(dgRow)
        Next

        Dim FormControls As New frmFacultyList.ControlCollection(frmFacultyList)


        For Each DGV As DataGridView In FormControls
            If WhichList.Name = DGV.Name Then
                DGV = WhichList
                DGV.Refresh()
            End If
        Next

    End Sub

这是他们传递信息的地方。同样,对于FLoad按钮单击,FormControls变量为空,但对于CLoad按钮单击则不是。任何帮助将不胜感激。

编辑:对不起,这是相关的公共属性

Public Property WhichList As New DataGridView
Public Property FilePath As String
Public Property DecryptedString As String
Public Property EncryptedString As String

1 个答案:

答案 0 :(得分:0)

转身我解决了自己的问题。保存功能未正确写入文件,因此无法正确提取信息。固定的。