How to add an item to ComboBoxEdit?

被刻印的时光 ゝ 提交于 2019-12-03 23:08:52

WIth this line :

Comboboxedit1.Properties.Items.Add(combo);

You are adding the ComboBox object inside itself. ComboBoxEdit ToString() method returns the name you are seeing in your screenshot.

So, remove this line.

Your code in taken from the official DevExpress documentation (except the line above that you should remove), and works fine : items are indeed added.

However, setting the SelectedIndex property to -1 doesn't select anything, as the documentation states :

The BaseListBoxControl.SelectedIndex property is set to -1 for demonstrative purposes (the property is set to -1 by default). This ensures that no item is currently selected in the combo box.

You can do :

combo.SelectedIndex = 0;  // Select Sven

Or

combo.SelectedIndex = 1;  // Select Cheryl

Or

combo.SelectedIndex = 2;  // Select Dirk

Use some like this:

try
{
    ComboBoxEdit combo = new ComboBoxEdit();

    combo.Properties.Items.Add("Sven, Petersen");
    combo.Properties.Items.Add("Cheryl, Saylor");
    combo.Properties.Items.Add("Dirk, Luchte");
}

Will work fine! No complication, no inovation, simple like need be!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!