|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How Does ComboBox Determine What To Display?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 On 2010-04-21, eBob.com <eBob.***@totallybogus.com> wrote:
Show quoteHide quote > I implemented as class like this ... The default behavior is to call Object.ToString(). You have not overriden> > 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 > ..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
Show quote
Hide quote
"Tom Shelton" <tom_shel***@comcastXXXXXXX.net> wrote in message Thank you Tom, I was confused about the meaning of "Shadows". That news:OCWdD%23Q4KHA.4804@TK2MSFTNGP04.phx.gbl... > On 2010-04-21, eBob.com <eBob.***@totallybogus.com> 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 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
vb.net 2008 display and print directory/subdirectories
Foreign Currency Exchange Rates Web service Get email with Visual Basic 2008 Draw an arrow on a line How to read a Stream into an XElement how to use a common class in different projects Importing data from web site search for a string or part of a string in another string algoritm special permutation Where is My.Settings? |
|||||||||||||||||||||||