Hi,
I would like to have a form class that is called from a button on a parent form and would like a button on the child form to set a property on the parent form. Can anyone explain the best way to go about this or direct me to a good article?
In the parent class:
One twist is the property in the parent class is a generic list(of T):
The object contained in the list is:
In the child form I would create a new object LayerToAdd and populate its three fields and then pass this to the parent class property to add to the list. At least this is the way I think I'm going to go about it. Any advice?
I would like to have a form class that is called from a button on a parent form and would like a button on the child form to set a property on the parent form. Can anyone explain the best way to go about this or direct me to a good article?
In the parent class:
VB.NET:
Private Sub cmdChngLineCls_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdChngLineCls.Click
m_sLayerType = "line"
Dim MyForm As New Project.ChooseHabParam(m_sLineLayer, m_sLayerType)
If MyForm.Form_Initialize(m_app) Then
MyForm.ShowDialog()
End If
End Sub
One twist is the property in the parent class is a generic list(of T):
VB.NET:
Private m_LLayersFields As List(Of LayerToAdd) = New List(Of LayerToAdd)
Public Property LHabParamList()
Get
Return m_LLayersFields
End Get
Set(ByVal value)
Dim pLayerToAdd As LayerToAdd
pLayerToAdd = value
Dim sLayer As String = pLayerToAdd.Layer
Dim comparer As New CompareLayerNamePred(sLayer)
' Need an object to hold returned object, if it exists...
Dim CheckedLayerToAddObj As LayerToAdd
Dim iIndex As Integer
' This find function will pass in the m_LLayersFields object to the comparerobject function
' which has its variable -_name- set above
CheckedLayerToAddObj = m_LLayersFields.Find(AddressOf comparer.CompareNames)
iIndex = m_LLayersFields.FindIndex(AddressOf comparer.CompareNames)
' If there is a match found then change the other parameters of the object
With CheckedLayerToAddObj
If .Layer IsNot Nothing Then
' Change the fields to equal incoming object's
.ClsField = pLayerToAdd.ClsField
.QuanField = pLayerToAdd.QuanField
' Now need to delete the old object and put it the modified one back into the list.
m_LLayersFields.Item(iIndex).ClsField = pLayerToAdd.ClsField
m_LLayersFields.Item(iIndex).QuanField = pLayerToAdd.QuanField
Else 'Otherwise just add the object to the list
m_LLayersFields.Add(pLayerToAdd)
End If
End With
End Set
End Property
The object contained in the list is:
VB.NET:
Public Class LayerToAdd
Public Layer As String
Public QuanField As String
Public ClsField As String
Public Sub New(ByVal layer As String, ByVal QuanField As String, ByVal ClsField As String)
Me.Layer = layer
Me.QuanField = QuanField
Me.ClsField = ClsField
End Sub
End Class
In the child form I would create a new object LayerToAdd and populate its three fields and then pass this to the parent class property to add to the list. At least this is the way I think I'm going to go about it. Any advice?