We help IT Professionals succeed at work.

How do i get a field from a combo box

Olukayode Oluwole
on
I have a c# application in which i need to get a field from a combo box.

See a table which i have loaded into a combo . (See table below)

Loaded Table with Data
What i want to grab are 2 fields  othercurrencycode   and  exchrate

Below is the script that does the Load and specifies the 2 fields  to get

  LoginDetails.exDataSource = GlobalConfig.Connection.GetExchRate_All();
  glTRANSCurrencyValue.DataSource = LoginDetails.exDataSource;
  glTRANSCurrencyValue.DisplayMember = "FullCodeName";
  glTRANSExchrateValue.DataBindings.Add(new System.Windows.Forms.Binding("Text", LoginDetails.exDataSource, "exchrate", true));
  glTRANSCurrencyValue.DataBindings.Add(new System.Windows.Forms.Binding("Text", LoginDetails.exDataSource, "othercurrencycode", true));

Below is short of the screen that shows the loaded Combo

Combo Load Display
The screen below shows that the Currency instaed is showing the ValueMember is showing the DisplayValue (see below)

Currecycode value showing display member instead of Valuemember
what do i need to specify to get the USD  as the code at runtime and not the complete record

Thanks

Oluaky
Comment
Watch Question

Microsoft Dynamics CRM Consultant
BRONZE EXPERT
Commented:
Hi,

Not sure if you have used any object to bind the combobox.

combobox.SelectedItem should give you selected object and from the object you can get the property.

https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.combobox.selecteditem?view=netframework-4.8

Commented:
As in the previous expert comment, not sure how you're using the objects..

If glTRANSCurrencyValue is your combobox id..

You are setting glTRANSCurrencyValue
DisplayMember,.. similarly

 try setting the currency code column result to
glTRANSCurrencyValue.ValueMember
Olukayode OluwoleSystems Analyst

Author

Commented:
Thanks Got it

Explore More ContentExplore courses, solutions, and other research materials related to this topic.