adding an item to a ComboBox

flynn

Regular
Joined
Jul 28, 2005
Messages
59
I am wanting to add an item to a combobox, so I thought I could do something like this:
Code:
dim cboItem as ComboBoxItem

cboItem = ComboBox1.add()

cboItem.text = "123"
cboItem.tag = "abc"

Is there a way to create a combobox item, then set the values of that item?

tia,
flynn
 
Create a class something like this...
C#:
public class ComboBoxItem
{
	private string _displayMember;
	private int _value;

	public ComboBoxItem(string text, int val)
	{
		_displayMember = text;
		_value = val;
	}

	public string DisplayMember
	{
		get { return _displayMember; }
		set { _displayMember = value; }
	}

	public int Value
	{
		get { return _value; }
		set { _value = value; }
	}
}
Then use it something like...
C#:
ComboBox comboBox1 = new ComboBox();

ComboBoxItem newItem1 = new ComboBoxItem("hello", 10);
ComboBoxItem newItem2 = new ComboBoxItem("Bob", 9);

comboBox1.DisplayMember = "DisplayMember";
comboBox1.ValueMember = "Value";

comboBox1.Items.Add(newItem1);
comboBox1.Items.Add(newItem2);
 
Back
Top