简体   繁体   中英

C# How to set default value of a string collection in Design

In WinForm, I have a combobox with DropDownStyle set to DropDownList (so can't enter a Text). In the properties window, there is the Items property which is a string collection. I enter all my values.

But now, I would like to set one of these value by default (instead to have the empty entry at run-time). I know how to do this via coding, but I am pretty sure (damn memory) that it was possible to set one of the value in the string collection as default by adding a special symbole in front of the line.

Anybody know that symbole? Or my memory is playing me trick and it is not possible to do it via the designer?

Doesn't look like it can be done when using a DropDownList. From here it is suggested that you can set the text property to the default value you want, but this will only works in a DropDown rather than DropDownList style.

I'm sorry but that is not possible within the Designer only, since the Text property is used for this feature and that property is ignored/cleared when the using a DropDownList.

If you don't mind having your data values outside of the Designer, you could probably use DataBinding to accomplish this since the DisplayMember and ValueMember properties of ComboBox can be used in the Designer and would set the display value. I don't normally use DataBinding so unfortunately I cannot provide code examples - perhaps another user can chime in?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM