Reputation: 2140
Hi can anyone help here? I am currently learning VB.net but for a project I need to create and array and pass it using a property. The data to be passed will be a train's destination, the time its due and the expected time of the train. I was wondering if someone could simplly explain how to first produce an array and then show how to pass it to a custom control using a property any help would be great.
Thank you.
Upvotes: 0
Views: 1495
Reputation: 25601
If you want to provide multiple values to a control, one clean way to do this is to have separate properties, one for each value, instead of trying to pass them all in one array. Another clean way to do this is to create a new class (type) that combines all these values into one structure, and expose a single property of that type. For example:
Public Class TrainDetails
Private _destination As String
Private _due As DateTime
Private _expected as DateTime
Public Property Destination As String
Get
Return _destination
End Get
Set
_destination = Value
End Set
End Property
Public Property Due As DateTime
Get
Return _due
End Get
Set
_due = Value
End Set
End Property
Public Property Expected As DateTime
Get
Return _expected
End Get
Set
_expected = Value
End Set
End Property
End Class
(Note, I think it's necessary to implement property procedures instead of directly exposing the internal field values in order for the properties to show up in a property grid.)
So if you have this class, then you can create a property of type TrainDetails on your control that will encapsulate all these properties in one value. I think they will be editable in the property grid as a single property with an expandable "+" next to it to edit the individual values.
Upvotes: 1