Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to populate a ToolStripComboBox?

Tags:

c#

.net

winforms

I find it hard binding data to a ToolStripComboBox. It seems it doesn't have the ValueMember and DisplayMember properties.

How to bind it?

like image 497
yonan2236 Avatar asked Jul 30 '10 05:07

yonan2236


2 Answers

To access the wrapped combobox in toolstripcombobox and gain access to its ValueMember/DisplayMember/DataSource you have to write something like this:

ToolStripComboBox1.ComboBox.ValueMember = "YourValueField";
like image 174
0x49D1 Avatar answered Oct 27 '22 01:10

0x49D1


You shouldn't set ToolStripComboBox1.ComboBox.DataSource = null

If you set ToolStripComboBox1.ComboBox.DataSource = null then you can try

ToolStripComboBox1.ComboBox.DataSource = null
ToolStripComboBox1.ComboBox.DisplayMember= "DisplayName"
ToolStripComboBox1.ComboBox.ValueMember = "Value"
ToolStripComboBox1.ComboBox.DataSource = dataSource
like image 22
Pham Avatar answered Oct 27 '22 00:10

Pham