仅在初始打开时设置组合框的默认索引 [英] Setting the default index of my combo box only on initial open
问题描述
According to that user, in the Delphi IDE, one is able to, in the Properties window, set the DEFAULT INDEX of a comboBox
when you open it INITIALLY. However, no where can I find Default Index
anywhere. When I mean initially, I mean not programmatically, and at the same time if and only if it's opened initially.
我尝试通过 comboBox.SelectedIndex = 0
设置索引,但事实证明,每次运行程序时我都会对其进行设置,因此不仅在最初,而且每次我运行程序的时间.不是我想要的.
I've tried setting the index through comboBox.SelectedIndex = 0
, but it turns out that I would be setting it every time I run the program, so that happens not only initially, but every time I run the program. Not what I want.
有人知道我可以在属性或参数事件窗口中做什么吗??
Does anyone know what I can do in the properties or argument events window on how I can do that..?
最初打开程序时,它是这样的:
When I open my program initially, this is what it looks like:
我的属性标签:
我可以创建一个全局整数计数器,该整数在每次运行时都会递增,并且当且仅当整数为0时才将默认值设置为0,这意味着它是第一次运行,但是如果我可以不这样做的话以编程方式进行,那会更好.
I could create a global integer counter which increments on each run, and have the default value set as 0 if and only if the integer is 0, meaning it's the first run, but if it's something I can do without doing it programmatically, that would be better.
推荐答案
如果要将组合框的特定索引设置为默认值,请在表单加载内设置索引,
If you want to set particular index of combobox as a default value set the index within form load,
private void Form1_Load(object sender, EventArgs e)
{
//To make combobox non editable
comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
//Set preferred index to show as default value
comboBox1.SelectedIndex = 2;
}
这篇关于仅在初始打开时设置组合框的默认索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!