P
Phil Jollans
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
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