VS2010 / C#:如何设置在IDE中组合框的默认值? [英] VS2010/C#: How do you set the default value of a ComboBox in the IDE?
问题描述
我正在写一个Windows窗体应用程序在C#中,使用Visual Studio 2010。
I'm writing a Windows Forms app in C#, using Visual Studio 2010.
它有一个组合框。我已经设置DropDownStyle为DropDownList的,并添加了几行,以项目
It has a combo box. I've set the DropDownStyle to "DropDownList", and added a few lines to "Items".
问:有什么办法,我在设置SelectedItemIndex了属性编辑器,因此在该行项目集合将出现在组合框中时,显示为默认?
Q: Is there any way for me to set SelectedItemIndex in the "Properties" editor, so that line in the "Items" collection will appear as the default when the combo box appears?
我知道我可以编程设置myComboBox.SelectedItemIndex = NNN在我的Form_Load方法,但我的确定的有可能是某种方式来做到这一点在MSVS IDE了。
I know I can programmatically set "myComboBox.SelectedItemIndex = NNN" in my Form_Load method, but I'm SURE there's probably some way to do it in the MSVS IDE, too.
任何想法?
感谢你在前进!
推荐答案
我不知道如果这是你问什么,但如果你想有一个特定的项目加载的形式设置为默认IE浏览器,且已存在为您选择的值。
I'm not sure if this is what your asking for but if you want a specific item to be set as default I.E you load the form and there is already a value selected for you.
简单地把这个变成你的公共Form1中()
方法。
Simply put this into your public Form1()
method.
comboBox1.SelectedItem = "Test1";
//comboBox1 change to the name of
//your combobox
//Test1 change to the item in your list of items that you want
//defaulted.
我认为这是迄今为止做的最好办法。
I think that is by far the best way to do it.
这篇关于VS2010 / C#:如何设置在IDE中组合框的默认值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!