仅在初始打开时设置组合框的默认索引 [英] Setting the default index of my combo box only on initial open

查看:47
本文介绍了仅在初始打开时设置组合框的默认索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

针对此问题:根据该用户,可以在Delphi IDE中的属性"窗口中设置 comboBox DEFAULT INDEX >打开它时 INITIALLY .但是,在任何地方都找不到 Default Index .当我最初指的是,我指的不是以编程方式,而是同时(且仅当)最初打开时.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆