现有组合框对象的数组 [英] Array of existing combo Box Objects

查看:124
本文介绍了现有组合框对象的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序有大约二十个值,其中的测量信息包含在下拉列表中。在这种情况下,值为:



该程序将用于转换一张混合的英制或公制值,并使它们全部为公制或相反的英制。下拉列表用于指示相关文本框中的度量标准或英制值。



为实现此目的,我想扫描我创建的所有下拉对象对于一个或另一个索引值的实例并执行转换以影响包含输入值的关联文本框。



我正在寻找一种方法在我的表单上为一个数组分配一些已经存在和命名的下拉控件,以便我可以使用循环处理它们。



我能找到很多设置索引或填充索引的例子,但没有创建一个组合框数组,除非它在运行时创建新的组合框。



任何线索?

My application has twenty or so values who's measurement information is contained in a drop down. In this case the values are:

The program will be used to convert a sheet of mixed imperial or metric values and make them all metric or conversely imperial. The drop down is used to indicate metric or imperial values in the associated textbox.

To achieve this I want to scan through all the drop down objects I have created to look for instances of one or the other index value and execute a conversion to affect the associated textbox containing the input value.

I'm looking for a way of assigning to an array a number of already existing and named drop Down controls on my form so that I can process them using a loop.

I can find lot of examples of setting the index or filling in the index, but none of creating an array of combo boxes unless its creating new ones at run time.

Any clues?

推荐答案

我看到许多应用程序具有20个这样的值,表示为适当数量的组合框,文本框和类似的控件。他们永远不够好。你说的只是UI设计不佳的迹象。



你需要创建一些更合理的UI设计。例如,它可以是具有可编辑单元格的网格视图。有许多不同的选择。由于您从未提及您正在使用的UI框架/库,我没有提及特定的控件类型。



-SA
I saw a number of applications having "twenty of so values" represented as appropriate number of combo boxes, text boxes and similar controls like that. They are never good enough. What you say is just the indication of poor UI design.

You need to create some more sensible UI design. For example, it could be a grid view with editable cells. There is a number of different options. As you never mentioned what UI framework/library you are using, I am not mentioning particular control types.

—SA


如果你知道他们的名字然后你可以通过类似的东西创建一个数组(检查我的语法):

If you know their names then you can create an array by something like (check my syntax):
CombBox[] myCombos = new ComboBox[]{"combo1", "combo2" ...};



或者,您可以遍历表单上的所有控件,并通过以下方式检查它是否为 ComboBox


Alternatively you can loop through all the controls on your form and check if it's a ComboBox by:

foreach (Control ctl in myForm.Controls)
{
    if (ctl.GetType() == typeof(ComboBox))
    {
        // do stuff to the combo items
    }
}


List<combobox> myCombos = new List<combobox>();

foreach(Control ctrl in this.Controls)
{
    if(ctrl is ComboBox)
        myCombos.Add(ctrl);
}



-KR


-KR


这篇关于现有组合框对象的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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