Link to home
Start Free TrialLog in
Avatar of chriscboy
chriscboyFlag for United Kingdom of Great Britain and Northern Ireland

asked on

How do I reference controls in in TabPage in C#

How do I reference controls that are in a TabPage of a TabControl?

 I have a TabControl called tabMain, and have created three TabPages called tabHazard,tabRisk,tabAction. Inside tabHazard I have a datagrid called dgridHazard. How would I reference this datagrid in code?

I thought it might be something like tabMain.tabHazard.dgridHazard but I'm not getting any joy.
ASKER CERTIFIED SOLUTION
Avatar of denbessonov
denbessonov
Flag of Russian Federation image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of chriscboy

ASKER

Lol I just discovered that as your message arrived!! I don't understand this because I thought the dgridhazard would be a child object of the TabControl and not the main form.
Avatar of Umar Topia
Try this
DataGrid dgid = tabMain.Controls[0].FindControl("dgridHazard") as DataGrid;

if it does not work then 

DataGrid dgid = tabMain.Items[0].FindControl("dgridHazard") as DataGrid;

Open in new window