Question Consuming WebService in windows forms application

sisquo76

Active member
Joined
Dec 1, 2008
Messages
28
Location
Bosnia and Herzegovina
Programming Experience
3-5
I added web reference to a project. Web Service has GetCountries web method and returns DataSet. I need those data in listbox. I figured how to do this, but i wonder is this a proper way?

VB.NET:
Public Class Form1
    Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        Dim a As New com.ezzylearning.www.CountryInformationService
        Dim Countries As DataSet = a.GetCountries
        Dim countryList As New List(Of String)
        For Each dr As DataRow In Countries.Tables(0).Rows
            countryList.Add(dr.Item(2).ToString)
        Next

        Me.ListBox1.DataSource = countryList
    End Sub
End Class
 
There's no point using that List(Of String). Just bind the DataTable to the ListBox:
ListBox1.DisplayMember = "NameOfColumnToDisplay"
ListBox1.ValueMember = "NameOfIDColumn"
ListBox.DataSource = Countries.Tables(0)
 
Back
Top