smaguire
asked on
Populating combobox with items and values from arrays
Hi,
I am trying to populate a combobox from 2 string arrays, the first array contains the name of the item and te second one contains the value of the item:
string[] RangeName;
string[] RangeValue;
RangeName = (new string[] { "Uni10Volts", "Uni5Volts", "Uni2Pt5Volts", "Uni2Volts"});
RangeValue = (new string[] { "100", "101", "102","103"});
so, when the user selects i.e Uni10Volts from the combobox, I want to be able to retrieve the value 100 when using the SelectedValue property. what do I need to add to the following code:
int i;
for (i = 0; i < RangeName.Length; i++)
{
this.cmbScanRange.Items.Ad d(RangeNam e[i]); //This will add the array to the combobox
// what do I need to add here
}
It was really easy in vb with the DataFieldValue and DataFieldText but I don't have such an options.
does anyone know how to accomplish this task?
thanks
I am trying to populate a combobox from 2 string arrays, the first array contains the name of the item and te second one contains the value of the item:
string[] RangeName;
string[] RangeValue;
RangeName = (new string[] { "Uni10Volts", "Uni5Volts", "Uni2Pt5Volts", "Uni2Volts"});
RangeValue = (new string[] { "100", "101", "102","103"});
so, when the user selects i.e Uni10Volts from the combobox, I want to be able to retrieve the value 100 when using the SelectedValue property. what do I need to add to the following code:
int i;
for (i = 0; i < RangeName.Length; i++)
{
this.cmbScanRange.Items.Ad
// what do I need to add here
}
It was really easy in vb with the DataFieldValue and DataFieldText but I don't have such an options.
does anyone know how to accomplish this task?
thanks
ASKER
WinForms ComboBox
I tried DisplayMember and ValueMember but I was getting always the last value added to the combobox
I tried DisplayMember and ValueMember but I was getting always the last value added to the combobox
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Very good.
thanks
thanks
WinForms ComboBox has DisplayMember and ValueMember.
Bob