Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / June 2007

Tip: Looking for answers? Try searching our database.

Binding names of ENUM constants to a Combobox

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Richard Tocci - 18 Jun 2007 22:46 GMT
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?
Signature

Richard Tocci
College Station, TX

Tim Van Wassenhove - 19 Jun 2007 16:28 GMT
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)
Herfried K. Wagner [MVP] - 19 Jun 2007 19:51 GMT
"Tim Van Wassenhove" <timvw@newsgroup.nospam> schrieb:
> 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))'.

Signature

M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.