//dataBinding via Name

 

                //clear each textbox before binding

                foreach (TabPage tp in tabControl_ProcA.TabPages)

                    foreach (Control ctl in tp.Controls)

                    {

                        if (ctl is TextBox)

                        {

                            ctl.DataBindings.Clear();

                            ctl.Text = "";

                        }

                    }

 

                //if control is a textbox then get name of current TabPage

                //and bind per controlName.

                //Some TabPages have more than one table to bind to

                //so take first three characters of name to determine proper table.

                foreach (TabPage tp in tabControl_ProcA.TabPages)

                    foreach (Control ctl in tp.Controls)

                    {

                        if (ctl is TextBox && ctl.Enabled == true)

                        {

                            if (tp.Name == "tabPage0_Estimate" || tp.Name == "tabPage0_Estimate2")

                            {

                                if (ctl.Name == "SHORTNAME" || ctl.Name == "LONGNAME" || ctl.Name == "CONTACT" ||

                                    ctl.Name == "PHONE" || ctl.Name == "MANHOUR" || ctl.Name == "CITY")

                                {

                                    ctl.DataBindings.Add(new Binding("Text", usmDataSet_EstimateProcedure1.Tables["company_info"], ctl.Name, true, DataSourceUpdateMode.OnPropertyChanged));

                                }

                                else if (ctl.Name == "SALES_TAX" || ctl.Name == "PROFIT_FACTOR" || ctl.Name == "PRIORITY")

                                {

                                    //do nothing for now

                                }

                                else

                                {

                                    ctl.DataBindings.Add(new Binding("Text", usmDataSet_EstimateProcedure1.Tables["estimates"], ctl.Name, true, DataSourceUpdateMode.OnPropertyChanged));

                                }

                            }

                            else if (tp.Name == "tabPage1_Cabinets6" || tp.Name == "tabPage1_Cabinets5")

                            {

                                if (ctl.Name.Contains("CAB"))

                                {

                                ctl.DataBindings.Add(new Binding("Text", usmDataSet_EstimateProcedure1.Tables["cabinet"], ctl.Name, true, DataSourceUpdateMode.OnPropertyChanged));

                                }

                                else if (ctl.Name.Contains("GIV"))

                                {

                                    ctl.DataBindings.Add(new Binding("Text", usmDataSet_EstimateProcedure1.Tables["given"], ctl.Name, true, DataSourceUpdateMode.OnPropertyChanged));

                                }

 

                            }

                            else if (tp.Name == "tabPage2_Cyl")

                            {

                               ctl.DataBindings.Add(new Binding("Text", usmDataSet_EstimateProcedure1.Tables["cylinder"], ctl.Name, true, DataSourceUpdateMode.OnPropertyChanged));

                            }

                            else if (tp.Name == "tabPage3_Pipes")

                            {

                                ctl.DataBindings.Add(new Binding("Text", usmDataSet_EstimateProcedure1.Tables["pipe"], ctl.Name, true, DataSourceUpdateMode.OnPropertyChanged));

                            }

                            else if (tp.Name == "tabPage4_AngleIrons")

                            {

                                ctl.DataBindings.Add(new Binding("Text", usmDataSet_EstimateProcedure1.Tables["angle_irons"], ctl.Name, true, DataSourceUpdateMode.OnPropertyChanged));

                            }

                            else if (tp.Name == "tabPage5_BarsRails")

                            {

                                if (ctl.Name.Contains("BAR"))

                                {

                                    ctl.DataBindings.Add(new Binding("Text", usmDataSet_EstimateProcedure1.Tables["bars"], ctl.Name, true, DataSourceUpdateMode.OnPropertyChanged));

                                }

                                else if (ctl.Name.Contains("RAI"))

                                {

                                    ctl.DataBindings.Add(new Binding("Text", usmDataSet_EstimateProcedure1.Tables["rail"], ctl.Name, true, DataSourceUpdateMode.OnPropertyChanged));

                                }

                            }

                            else if (tp.Name == "tabPage6_Beams")

                            {

                                if (ctl.Name.Contains("BEA"))

                                {

                                    ctl.DataBindings.Add(new Binding("Text", usmDataSet_EstimateProcedure1.Tables["beams_channels"], ctl.Name, true, DataSourceUpdateMode.OnPropertyChanged));

                                }

                                

                            }

                            else if (tp.Name == "tabPage7_Circum")

                            {

                                ctl.DataBindings.Add(new Binding("Text", usmDataSet_EstimateProcedure1.Tables["circumference"], ctl.Name, true, DataSourceUpdateMode.OnPropertyChanged));

                            }

                            else if (tp.Name == "tabPage8_Diam")

                            {

                                ctl.DataBindings.Add(new Binding("Text", usmDataSet_EstimateProcedure1.Tables["diameter"], ctl.Name, true, DataSourceUpdateMode.OnPropertyChanged));

                            }

                        }

                    }

            }

            catch (Exception ex)

            {

                throw ex;

            }

            finally

            {

                switchSelectedIndexDelegate("on");

            }

        }