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_SelectedValueCha nged(objec t sender, System.EventArgs e)
{
if(comboBox1.SelectedIndex != -1)
Console.WriteLine(comboBox 1.Selected Value.ToSt ring());
else
label2.Text=load[comboBox1 .SelectedI ndex].ToSt ring();
}
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?
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_SelectedValueCha
{
if(comboBox1.SelectedIndex
Console.WriteLine(comboBox
else
label2.Text=load[comboBox1
}
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?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
access comboBox1.SelectedItem (which is the array element if you used databinding)