PC Review


Reply
Thread Tools Rate Thread

How Does ComboBox Determine What To Display?

 
 
eBob.com
Guest
Posts: n/a
 
      21st Apr 2010
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





 
Reply With Quote
 
 
 
 
Tom Shelton
Guest
Posts: n/a
 
      21st Apr 2010
On 2010-04-21, eBob.com <(E-Mail Removed)> wrote:
> 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
>


The default behavior is to call Object.ToString(). You have not overriden
..ToString - but have shadowed it's implementation. So, the default object
implmentation will be used. Shadows only hides the parent implementation from
your descendants.

--
Tom Shelton
 
Reply With Quote
 
eBob.com
Guest
Posts: n/a
 
      21st Apr 2010

"Tom Shelton" <(E-Mail Removed)> wrote in message
news:OCWdD%(E-Mail Removed)...
> On 2010-04-21, eBob.com <(E-Mail Removed)> wrote:
>> 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
>>

>
> The default behavior is to call Object.ToString(). You have not overriden
> .ToString - but have shadowed it's implementation. So, the default object
> implmentation will be used. Shadows only hides the parent implementation
> from
> your descendants.
>
> --
> Tom Shelton


Thank you Tom, I was confused about the meaning of "Shadows". That
confusion came in part from a compiler/VS message! If my definition of the
ToString property omits "Shadows" then I get the message: "property
'ToString' conflicts with function 'ToString' in the base class 'Object' and
should be declared 'Shadows'". I would say that 'Shadows' in this case
didn't really resolve the conflict, or at least permitted an ambiguity.

Thanks again for your help, Bob

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
API Call to determine value of ComboBox? Joe HM Microsoft VB .NET 2 17th Jan 2007 08:39 PM
Combobox to determine text for a range of cells =?Utf-8?B?Um9iYnlu?= Microsoft Excel Programming 0 26th Jun 2006 03:18 PM
Determine if report is in display mode Pete Microsoft Access 1 10th Feb 2006 10:44 PM
Display a combobox depending on another combobox Veli Izzet Microsoft Access 2 11th Aug 2005 07:25 AM
Determine source of text control of a combobox Michael Jackson Microsoft Dot NET Framework Forms 1 3rd Aug 2005 07:18 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:55 PM.