Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1290
How do I programmatically create/add controls within tabs
posted

Hi,

I'm trying to programmatically create tabs, and then add some controls to it but i'm having some issues I hope I can get some help with.

 

foreach (DataRow row in dtModules.Rows)

            {

                string tabName = row["mod_Name"].ToString();

                utMainTab.Tabs.Add(tabName, tabName);

                string imagePath = APPLICATION_PATH + "Images\\" + row["mod_Image"].ToString();

                utMainTab.Tabs[tabName].Appearance.Image = Image.FromFile(imagePath);

                utMainTab.ImageSize = new Size(20, 20);

                Label lbl = new Label();

                lbl.Text = "new";

                utMainTab.Controls[tabName].Controls.Add(lbl);

            }

 

I get a NullReferenceException on the last line:                 

utMainTab.Controls[tabName].Controls.Add(lbl);