displaying key-value pairs in comboboxes

  • Thread starter Thread starter Nikhil Patel
  • Start date Start date
N

Nikhil Patel

Hi All,
I am using a dll function that returns a two diamensional array
containing BankNames and RoutingIds. I need to display BankNames and
RoutingIds in two different comboboxes. When user selects an item in any of
these two comboboxes, I need to pick the matching item in another combobox.
Right now I store the values in a module level two diamensional array and
when user selects a bankname or routingid I loop through the array to find a
matching value. Is there any way to avoid looping through the array. I
thought I could use an ArrayList. But since all of the items will be string,
I don't think using ArrayList is good idea. Has anyone written a
StringArrayList? Is there any other better way to do this?

Thanks.
 
Try this code:

public class ValuePair
{
private string _s1;
private string _s2;

public ValuePair(string s1, string s2)
{
_s1 = s1;
_s2 = s2;
}

public string S1
{
get { return _s1; }
}
public string S2
{
get { return _s2; }
}
}

ArrayList list = new ArrayList();

list.Add(new ValuePair("s1","1"));
list.Add(new ValuePair("s2","2"));
list.Add(new ValuePair("s3","3"));
list.Add(new ValuePair("s4","4"));
list.Add(new ValuePair("s5","5"));
list.Add(new ValuePair("s6","6"));

comboBox1.DisplayMember = "S1";
comboBox1.ValueMember = "S1";
comboBox1.DataSource = list;

comboBox2.DisplayMember = "S2";
comboBox2.ValueMember = "S2";
comboBox2.DataSource = list;

With this code, setting one combobox to "s4" makes the other one show "4".


Chris
 
Back
Top