Binding names of ENUM constants to a Combobox

G

Guest

I'm learning Visual Basic using the .Net Framework 2.0. I have been playing
with consuming web services in applications.

I am using a free web service that gives me information for currency
conversion. The web service I am using is:

http://www.webservicex.net/CurrencyConvertor.asmx?WSDL

It's got pretty much everything I need, but I'm running into trouble.

I want 2 comboboxes in the application. Both of them need to contain the
names of the currencies that provide conversion factors. The names of the
currencies are 3 letter names that are names of are ENUM constants.

The function that provides the copnversion factor takes 2 arguments -- The
currency we're converting FROM, and the currency we're converting TO.

I'm trying to get the constant names in the dropdowns.

Here's the code so far:

Imports CurrencyConversion.wsCurrency.CurrencyConvertor
Imports CurrencyConversion.wsCurrency.Currency
Imports System.Windows.Forms



Public Class frmMain

Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim wsCurrencyNames As CurrencyConversion.wsCurrency.Currency

Dim arrayCurrencyName As New ArrayList()
'For Each wsCurrencyNames In
CurrencyConversion.wsCurrency.Currency.GetNames(GetType(wsCurrency.Currency))
'cbxFromCurrency.Items.Add(wsCurrencyNames.ToString())
'cbxToCurrency.Items.Add(wsCurrencyNames.ToString())
'Next

'cbxFromCurrency.DataSource =
System.Enum.GetNames(typeof(CurrencyConversion.wsCurrency.Currency))
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim dblRate As Double
Dim wsConvert As New wsCurrency.CurrencyConvertor
dblRate = wsConvert.ConversionRate(GBP, USD)
rtbResults.Text = CStr(dblRate)
End Sub
End Class


This line:
dblRate = wsConvert.ConversionRate(GBP, USD)

is the function that does work when values are entered directly. But I want
the user to choose from the list. Any ideas?
 
T

Tim Van Wassenhove

Something like this? (Perhaps it's time that i learn some vb.net)

' load data in the comboboxes...
cbxFromCurrency.DataSource =Enum.GetNames(typeof(Currency))
cbxToCurrency.DataSource = Enum.GetNames(typeof(Currency))

' handle conversion...
Currency from = CType(cbxFromCurrency.SelectedItem, Currency)
Currency to = CType(cbxToCurrency.SelectedItem, Currency)

blRate = wsConvert.ConversionRate(from, to)
 
H

Herfried K. Wagner [MVP]

Tim Van Wassenhove said:
Something like this? (Perhaps it's time that i learn some vb.net)

' load data in the comboboxes...
cbxFromCurrency.DataSource =Enum.GetNames(typeof(Currency))
cbxToCurrency.DataSource = Enum.GetNames(typeof(Currency))

=> '... = [Enum].GetNames(GetType(Currency))'.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top