0

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

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
4

1 回答 1

0

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

于 2012-04-02T15:15:16.530 回答