Link to home
Start Free TrialLog in
Avatar of Jimbo456
Jimbo456

asked on

Problem using an array.

I created an array (using ArrayList()) called load when my form loads. I use the array as values for my combobox.
I am trying to use this array to assign a value to a text box when the combobox value is selected using the following code.

public void comboBox1_SelectedValueChanged(object sender, System.EventArgs e)
             {
                
      if(comboBox1.SelectedIndex != -1)
        Console.WriteLine(comboBox1.SelectedValue.ToString());
      else
        label2.Text=load[comboBox1.SelectedIndex].ToString();
                  
             }

My problem is I am from the old school and can't make my array Public. What would be a work around for this? Can someone shed some light on the theory why its like this?
Avatar of gregoryyoung
gregoryyoung
Flag of Canada image

if(comboBox1.SelectedIndex != -1)
    access comboBox1.SelectedItem (which is the array element if you used databinding)
o yeah also your code will crash most likely since it will only ever try to access the array at element[-1]
ASKER CERTIFIED SOLUTION
Avatar of caner_elci
caner_elci

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