Passing a collection from a child form to the parent form

johnpapa

Member
Joined
Aug 10, 2013
Messages
23
Programming Experience
10+
I have managed to pass a string as follows:

In Child form (frmTime):

VB.NET:
    Dim strmTime As String    'Module variable
 
    Public Function fungResultTime() As String
        Return strmTime
    End Function
 
    Public Sub New(ByVal strTime)
        MyBase.New()
        InitializeComponent()
        strmTime = strTime
    End Sub

In Parent form
VB.NET:
   Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim frm = New frmTime(TextBox1.Text)
        frm.ShowDialog()
        TextBox1.Text = frm.fungResultTime
    End Sub


For passing a Collection I have in the Child form
Dim colWorkCode As New AutoCompleteStringCollection() 'Module level

I populate the collection in the Child form
VB.NET:
colWorkCode.Clear()
For i As Integer = 0 To dgv.Rows.Count - 1
If dgv.Rows(i).Cells("bitSelection").Value = True Then
colWorkCode.Add(dgv.Rows(i).Cells("nvcWorkCode").Value)
End If
Next

I do not know how to pass the collection back to the parent form.

Any help would be appreciated.

John
 
It's exactly the same regardless of the type. If you currently have a function with return type String to expose the String then you would use a function with return type AutoCompleteStringCollection to expose an AutoCompleteStringCollection. Preferably though, you would use a read-only property in both cases.
 
Thanks for the reply.

For the sake of completeness the following works.

CHILD
VB.NET:
Public colWorkCode As New AutoCompleteStringCollection

    Public Function fungabc() As AutoCompleteStringCollection
        Return colWorkCode
    End Function

PARENT
VB.NET:
Dim colWorkCode As AutoCompleteStringCollection
        colWorkCode = frm.fungabc
 
Back
Top