+ Reply to Thread
Results 1 to 2 of 2

Thread: create a tab control with a dynamic number of tabs

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    14

    create a tab control with a dynamic number of tabs

    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 would show tabs with the first letters of customers' last name (only those first letters, for which there are entries in the table should be present). Each tab should contain a DataGrid control with the corresponding customers. I connect to the database using DataSet.

    Where should I insert the code snippet that would generate such tabs? Can I do that with the existing tab control or should I create a custom control?

  2. #2
    Junior Member
    Join Date
    Jun 2012
    Posts
    14
    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);

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts