Hi there,
I have created a custom class called XmlSource which has a ToString() function .
vb Code:
Public Class XmlSource Inherits System.Net.WebClient Private _name As String Private _uri As Uri Private _xmldoc As System.Xml.XmlDocument Public Sub New(ByVal name As String, ByVal uri As Uri) MyBase.New() _name = name _uri = uri End Sub Public Sub New(ByVal name As String, ByVal uri As String) MyBase.New() _name = name _uri = New Uri(uri) End Sub Public Overrides Function ToString() As String Return _name End Function Public ReadOnly Property XmlDoc() As System.Xml.XmlDataDocument Get Return _xmldoc End Get End Property Public Property Uri() As Uri Get Return _uri End Get Set(ByVal value As Uri) _uri = value End Set End Property Public Property Name() As String Get Return _name End Get Set(ByVal value As String) _name = value End Set End Property Protected Overrides Sub OnDownloadStringCompleted(ByVal e As System.Net.DownloadStringCompletedEventArgs) 'If the string request went as planned and wasn't cancelled: If e.Cancelled = False AndAlso e.Error Is Nothing Then 'Use e.Result to get the String Dim sr As New System.IO.StringReader(CStr(e.Result)) ' The XmlTextReader Dim xr As New System.Xml.XmlTextReader(sr) ' The XmlDocument _xmldoc = New System.Xml.XmlDocument _xmldoc.Load(xr) End If MyBase.OnDownloadStringCompleted(e) End Sub Public Sub fetchXML() 'Fetch HTML page MyBase.DownloadStringAsync(_uri) End Sub End Class
In my MainForm_Load sub I am attempting to create a new instance and use it as follows:
vb Code:
Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim sourceUS As New XmlSource("US", "http://www.worldofwarcraft.com//realmstatus/status.xml") MsgBox(sourceUS) ComboBox_Continent.Items.Add(sourceUS)
The ComboBox_Continent.Items.Add() function doesn't complain but shows nothing in the control either. The MsgBox() does complain (I Added it for debug purposes). It tells me that Argument 'Prompt' cannot be converted to type 'String'. I was under the impression that was what the ToString() function was for.
Does anyone have any pointers?
Thanks,
Mightor




Reply With Quote