SoFunction
Updated on 2025-03-06

Winform dynamically loading TabControl usage example

This article describes the usage of Winform dynamically loading TabControl. Share it for your reference.

The specific implementation code is as follows:

Copy the codeThe code is as follows:

private void BindTabData()
{
    dtIPD = new DataTable();
    //drItem = new DataTable();
//Get the [Project Category] list displayed in TabPage
    MRD_Score model = new MRD_Score();
    = "Y";
    DataTable dtScore = (model);
    foreach (DataRow dr in )
    {
 MRD_Score sr = new MRD_Score();
  = dr["ProCode"].ToString();

 TabPage tabpage = new (dr["ProName"].ToString().Trim());
  = dr["ProName"].ToString().Trim();
  = true;
  = dr["ProName"].ToString().Trim();
//Get the defect item list under the major category txtIPD_NO.()
       DataTable  drItem = (, "");
("Defects", ("System.Int32"));
("Audited", ("System.Int32"));
("Scoring time", (""));
("Rating Person", (""));
("Audit time", (""));
("Approval", (""));
 DataGridView dgv = new DataGridView();
= false;//Disable new addition
= false; //Disable deletion
  = 960;
  = 600;
  = ;

+= new DataGridViewCellValidatingEventHandler(dgv_CellValidating);//Verify whether it is a number
+= new DataGridViewCellCancelEventHandler(dgv_CellBeginEdit);// Set whether it can be edited
  += new DataGridViewCellEventHandler(dgv_CellEndEdit);
 // += new DataGridViewCellFormattingEventHandler(dgv_CellFormatting);
  = drItem;
 dtIPD = (, txtIPD_NO.());
 (dgv);
 this.(tabpage);
SetInputValue(dgv, dtIPD);//Load the already entered score
 total += getDeFen(dgv, dtIPD);

 ["PCode"].Visible = false;
 ["ItemCode"].Visible = false;
["Rating Person"].Visible = false;
["Reviewer"].Visible = false;
    }
}

Copy the codeThe code is as follows:

private void GetTolSum()
{
    if ( == 0)
    {
 ();
 ();
 return;
    }
    double tolsource = 0.00;
    for (int i = 0; i < ; i++)
    {
 if (![i].HasChildren)
 {
     continue;
 }
 tolsource += SumDgv((DataGridView)[i].Controls[0]);
    }
    GetScoreLevel(tolsource);
    SaveTol();

}

I hope this article will be helpful to everyone's C# programming.