Creating a tab control with a dynamic number of tabs in Visual Studio C#

后端 未结 4 563
名媛妹妹
名媛妹妹 2021-01-04 21:17

How to create a tab control with a dynamic number of tabs in Visual Studio C#?

I\'ve got a database with a table customers. I need to create a form that

4条回答
  •  臣服心动
    2021-01-04 21:22

    You can generate dynamic tabs with the existing TabControl. Here is an example of how it can be done in a somewhat sort of pseudo code form...

    TabControl tabControl = new TabControl();
    tabControl.Dock = DockStyle.Fill;
    
    foreach (Char c in lastNameList)
    {
        TabPage tabPage = new TabPage();
        tabPage.Text = c.ToString();
    
        DataGrid grid = new DataGrid();
    
        grid.Dock = DockStyle.Fill;
        grid.DataSource = dataForTheCurrentLoop;
    
        tabPage.Controls.Add(grid);
        tabControl.Controls.Add(tabPage);
    }
    
    this.Controls.Add(tabControl);
    

提交回复
热议问题