Question

I can't find an answer to this anywhere. I define a new instance of a forms control collection, but at runtime, the collection is empty. It works for one load button on the form, but not another. The code is exactly the same, but one works, the other doesn't. Here is the relevant code:

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

This load button not loading

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

This one is.

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

Here is where they pass the info to. Again, the FormControls variable is empty for FLoad button click, but not for CLoad button click. Any help would be appreciated.

Edit: Sorry, here are the relevant Public Properties

Public Property WhichList As New DataGridView
Public Property FilePath As String
Public Property DecryptedString As String
Public Property EncryptedString As String
Was it helpful?

Solution

Turns I solved my own problem. The Save Function wasn't writing to the file correctly, so it wasn't pulling the information correctly. Fixed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top