I am currently working on a project and need to allow the user to create tabs. This I have managed to do although the solution (to copy from another hidden tab).

The problem I have is that I need the tabs being displayed to change between records (something that does not happen).

Is there a way of doing this or even a better solution?

I am using VB.net and SQL 2005.

Thanking you in advance for your assistance.

Dani AI

Generated

This thread is asking how to have the set of tabs change with the active record (VB.NET + SQL Server 2005). described creating tabs from a hidden template, and rightly pointed out a simple dynamic-tab example and suggested DataGridView as an alternative. A maintainable pattern that fits the requirement is to store “which tabs belong to which main record” in the data model, and drive the TabControl from that model while keeping each tab’s UI self-contained.

A practical workflow:

  1. Persist tab definitions (example columns: TabDefID, ParentRecordID, Title, ContentType, DataKey, SortOrder). This lets the application query exactly which tabs belong to the current main record.
  2. Build a single reusable UserControl (a “tab content” panel) that exposes a Load(recordId, tabDef) method and can render different ContentTypes (grid, form, text, image). Embed an instance of that control into each TabPage rather than scattering logic across many controls.
  3. When the main record changes, query tab definitions for that record, clear or recycle TabPages, set each TabPage.Text from the Title and store the TabDefID (or a small object) in TabPage.Tag. Either eagerly call Load on each control or lazy-load on SelectedIndexChanged to keep startup snappy.
  4. Use parameterized queries and background threads (Task/BackgroundWorker), then marshal results back to the UI thread. Dispose removed controls and detach handlers to avoid leaks.

Cautions and UX notes:

  • Don’t pull all tab content synchronously on the UI thread (causes freezes).
  • If the per-record tab sets vary a lot or there are dozens of tabs, consider an accordion/list + single details panel instead of many TabPages for better usability and performance.
  • For a quick prototype, re-creating TabPages on record change is fine; for production, prefer the data-driven UserControl + lazy-loading approach to keep code testable and maintainable.

Recommended Answers

All 8 Replies

Member Avatar for Member #46692

You mean something like?

That looks like it will help with the creation of the tabs iamthwee and I will try this later.

Does it allow for different tabs for each file?

Member Avatar for Member #46692

What do you mean for each file?

What I mean is that the tabs are going to show details from a SQL table.

The use wants to be able to only show the tabs necessary for the main record shown, so this may need to change as the users goes from record to record.

Does this help/make sense?

Member Avatar for Member #46692

This doesn't really make any sense. I've never personally seen any system designed like that.

DatagridView would be the obvious option for displaying information from a database. All this dynamic tab creation sounds illogical to me?

I quite agree with you, but it is what the person wants.

Is it possible to rename tabs on a regular basis?

Member Avatar for Member #46692

I don't know if this is what you are looking for but:

1. Create a new form and drag a tabControl onto it. Call it TabPage1
2. Create a text box call it TextBox1
3. Create two buttons call it Button1,Button2 respectively.

Paste in the code:

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        TabControl1.Controls.Add(New TabPage(TextBox1.Text))

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        TabControl1.SelectedTab.Text = TextBox1.Text
    End Sub
End Class

Basically it allows you create new tabs on the fly and if you click on a tab and type a name into the text box it renames that tab?

The following link might be of use although I've not looked at it?

Thanks once again iamthwee.

I am busy today, but will have a look in details later.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.