Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I am wanting to add an item to a combobox, so I thought I could do something like this:

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

Posted

Create a class something like this...

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...

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);

Anybody looking for a graduate programmer (Midlands, England)?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...