Re: Can't override CultureInfo.ToString
- From: "Jay B. Harlow" <Jay_Harlow_MVP@xxxxxxxxxxxxx>
- Date: Wed, 1 Nov 2006 20:08:11 -0600
Phil,
What does your C# code look like?
My understanding is that the ListBox will use the ToString() method toThat is my understanding also. Although using your code I get the same results. It feels like a bug. Have you submitted something on http://connect.microsoft.com/
generate the text shown in the list box. However, the ToString() method is
never entered.
The following demonstrates that your code is working:
Dim item As CultureInfo
item = New CultureListInfo("de")
Debug.WriteLine(item, "Object.ToString()")
Debug.WriteLine(item.ToString(), "CultureInfo.ToString()")
Prints:
Object.ToString(): Deutsch
CultureInfo.ToString(): Deutsch
Have you considered simply:
Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
MyBase.OnLoad(e)
ListBox1.Items.Add(New CultureInfo("de"))
ListBox1.Items.Add(New CultureInfo("es"))
ListBox1.Items.Add(New CultureInfo("fr"))
ListBox1.DisplayMember = "NativeName"
End Sub
--
Hope this helps
Jay B. Harlow
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Phil Jollans" <nospam@xxxxxxxxxxx> wrote in message news:ei32ug$2ot$03$1@xxxxxxxxxxxxxxxxxxxx
Hi,
I am having difficulty overriding the ToString() method of CultureInfo using
Visual Studio 2005.
Exactly the same code works fine with Visual Studio .NET 2003.
What I am doing is adding objects which are derived from CultureInfo to a
ListBox. I want the language name to be displayed in the native language, so
I override the ToString() method to access the CultureInfo.NativeName
property.
I can reproduce the problem with a simple example.
Create a windows forms project in VB.NET and add a single list box to the
form.
Paste the following code into the file Form1.vb (replacing the existing
code).
Imports System.Globalization
Public Class Form1
Private Class CultureListInfo
Inherits CultureInfo
Public Sub New ( Byval Name as String )
MyBase.New ( Name )
End Sub
Public Overrides Function ToString() as String
return NativeName
End Function
End Class
Private Sub Form1_Load( ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
ListBox1.Items.Add ( new CultureListInfo ( "de" ) )
ListBox1.Items.Add ( new CultureListInfo ( "es" ) )
ListBox1.Items.Add ( new CultureListInfo ( "fr" ) )
End Sub
End Class
My understanding is that the ListBox will use the ToString() method to
generate the text shown in the list box. However, the ToString() method is
never entered.
I have almost identical code in C# which works fine, and the above code
worked with VS 2003.
What is wrong?
Phil
.
- Follow-Ups:
- Re: Can't override CultureInfo.ToString
- From: Phil Jollans
- Re: Can't override CultureInfo.ToString
- Prev by Date: Re: How to set OpenFileDialog to "My Computer"
- Next by Date: RE: Problems when try to launch word in server 2003
- Previous by thread: How to set OpenFileDialog to "My Computer"
- Next by thread: Re: Can't override CultureInfo.ToString
- Index(es):
Relevant Pages
|