C#枚举dataSets和dataGridViews [英] C# Enumerating through dataSets and dataGridViews
问题描述
大家好,
我大约有10个标记为dataSet0..dataSet9的数据集.谁知道我不使用他们的名字就可以引用他们的属性和事件.我希望可以对它们进行索引,以便可以调用它们的属性和事件,但是我尝试通过表单控件进行枚举,以查看数据集是否将是这样的控件:
Hi all,
I have about 10 datasets labeled dataSet0..dataSet9. Would anyone know how I can reference their properties and events without using their names. I was hoping they would be indexed so I can call their properties and events but I tried to enumerate through the forms controls to see if the dataset would be a control as such:
for(int cc=0; cc < MyApp.MainForm.ActiveForm.Controls.Count; cc++)
MessageBox.Show(MyApp.MainForm.ActiveForm.Controls[cc].Name);
结果仅显示按钮和其他项目,不包括数据集或datagridviews.
我在应用程序中有10个选项卡,每个选项卡都有一个dataGridView和关联的数据集,我想在用户在用户选择的选项卡上选择网格后处理用户从网格中所做的选择.
这有意义吗?我需要更清楚地解释它吗?有人提到了集合,但是我迷失了如何设置集合,或者它是否真的可以完成我在引用属性&时需要做的事情.事件.
谢谢,
迈克
注意:我正在使用SharpDevelop
The result only showed the buttons and other items not including the datasets or datagridviews.
I have 10 tabs in the app, each with a dataGridView and associated dataset, and I want to process the users selection from the grid after they select it on a user selected tab.
Does this make sense? Do I need to explain it more clearly? Someone mentioned collections but I was lost on how to set that up or if it will actually do what I need to do with referencing the properties & events.
Thanks,
Mike
Note: I''m using SharpDevelop
推荐答案
数据集不是控件:因此不能出现在
A DataSet is not a control: therefor is cannot appear in a
Controls
数组中.只有从Control派生的对象才能显示,并因此以任何形式的Controls
枚举出现.
我会改变这样做的方式:使用DataSet数组(或者优先选择List< DatsSet>),而不用担心自己的名字.
或者,使用TabPage.Tag字段来引用适当的数据集.
array. Only objects which derive from Control can be displayed, and thus appear in a Controls
enumeration of any form.
I would change the way I was doing this: use an array of DataSets (or a List<DatsSet> by preference) and not comcern myself with the names at all.
Alternatively, use the TabPage.Tag field to reference the appropriate DataSet.
这篇关于C#枚举dataSets和dataGridViews的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!