Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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);


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
Posted
Updated 30-Jun-11 6:15am
v2
Comments
theanil 30-Jun-11 14:06pm    
datassets and datagridveiw are data controls they will not be shown in form comtrol

1 solution

A DataSet is not a control: therefor is cannot appear in a
Controls 
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900