Link to home
Start Free TrialLog in
Avatar of Olukayode Oluwole
Olukayode OluwoleFlag for Canada

asked on

How can i get a record from my combobox into a string variable

I have c# application in which i am trying to get records from
a combobox into a string variable.

The combo loads at Form load  ( see screen below )

User generated image
I the tried to select any of the records into a string variable  and some how
my string variable instead of  having data from the combo has an error  statement
about my Model  (see error page )

User generated image
I then tried to  use the debugger to find out if the record i selected is somewhere in memory
and indeed it showed up  (see  debugger output)

User generated image
How do i get the combo record out to my string variable.

Below is the Script that i am using to select the record from the combo and putting it in a string
variable

[private void glTRANSCurrencyValue_SelectedIndexChanged(object sender, EventArgs e)
        {
            // Setting index to 0 at form load ensure that script below is not processed during combo initial load
            if (this.glTRANSCurrencyValue.SelectedIndex != 0)
            {
                string phrase = glTRANSCurrencyValue.SelectedItem.ToString();
                string[] words = phrase.Split(' ');
                int i = 0;
                foreach (var word in words)
                {
                    i += 1;

                    if (i == 1)
                    {
                        decimal var1 = Convert.ToDecimal($"{word}");
                        glTRANSExchrateValue.Text = Convert.ToString(var1);

                    }

                }
            }
        }[/code]

How do i get the combo record into the string variable


Thanks

Olukay
ASKER CERTIFIED SOLUTION
Avatar of Lukasz Zielinski
Lukasz Zielinski
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Olukayode Oluwole

ASKER

I tried


            System.Data.DataRowView selected_row = comboBox1.SelectedItem as System.Data.DataRowView;
            textBox1.Text = selected_row["FieldName1"].ToString();

but selected_row was null even though I selected a row.  See  screen below

User generated image
Did i do anything wrong ??

I will try the second option  and get back to you.

But while i try that are you on TeamViewer  so we can sort this out in real time

Thanks

Olukay
Hi,
I was out for weekend.
Did you manage to solve it?

ziolko
Yes I did but ran into a different problem . I will post this shortly thanks