E
eBob.com
I implemented as class like this ...
Public Class ComboxChoice
Public ChoiceText As String
Public LastUsed As Date
Public UsedCount As Integer
'to be serializable we have to have a parameterless constructor
Sub New()
End Sub
Sub New(ByRef Choice As String, ByRef LastUsed As Date, _
ByVal UsedCount As Integer)
Me.ChoiceText = Choice
Me.LastUsed = LastUsed
Me.UsedCount = UsedCount
End Sub
Public Shadows ReadOnly Property ToString() As String
Get
Return Me.ChoiceText
End Get
End Property
'Public Overrides Function tostring() As String
' Return ChoiceText
'End Function
End Class
.... and I don't know what I was thinking when I made ToString a property
rather than a function. BUT this ...
MsgBox(New ComboxChoice("1st choice", DateTime.Now, 1).ToString)
.... gave the expected result, i.e. "1st choice", while this ...
cbx1.Items.AddRange(New Object() {New ComboxChoice("1st choice",
DateTime.Now, 1), _
New ComboxChoice("2nd choice",
DateTime.Now, 1)})
.... (where cbx1 is a ComboBox) does not - i.e. the items in the combobox do
not appear as "1st choice" and "2nd choice". I understand that ComboBox is
seeing the items as having a type of Object while in the MsgBox statement
ToString is clearly a member of ComboxChoice. But what kind of invocation
is ComboBox doing which manages to get the Object .ToString function rather
than my objects ToString property? Isn't "Shadows" supposed to completely
hide any ToString member in Object?
Thanks, Bob
Public Class ComboxChoice
Public ChoiceText As String
Public LastUsed As Date
Public UsedCount As Integer
'to be serializable we have to have a parameterless constructor
Sub New()
End Sub
Sub New(ByRef Choice As String, ByRef LastUsed As Date, _
ByVal UsedCount As Integer)
Me.ChoiceText = Choice
Me.LastUsed = LastUsed
Me.UsedCount = UsedCount
End Sub
Public Shadows ReadOnly Property ToString() As String
Get
Return Me.ChoiceText
End Get
End Property
'Public Overrides Function tostring() As String
' Return ChoiceText
'End Function
End Class
.... and I don't know what I was thinking when I made ToString a property
rather than a function. BUT this ...
MsgBox(New ComboxChoice("1st choice", DateTime.Now, 1).ToString)
.... gave the expected result, i.e. "1st choice", while this ...
cbx1.Items.AddRange(New Object() {New ComboxChoice("1st choice",
DateTime.Now, 1), _
New ComboxChoice("2nd choice",
DateTime.Now, 1)})
.... (where cbx1 is a ComboBox) does not - i.e. the items in the combobox do
not appear as "1st choice" and "2nd choice". I understand that ComboBox is
seeing the items as having a type of Object while in the MsgBox statement
ToString is clearly a member of ComboxChoice. But what kind of invocation
is ComboBox doing which manages to get the Object .ToString function rather
than my objects ToString property? Isn't "Shadows" supposed to completely
hide any ToString member in Object?
Thanks, Bob