Tab Control Design and coding Help needed!

H

Hexman

Off on another journey through vb.net.

What I want to do now is have a tab-control with 1 to 8 tab-pages for
categories. I've read where there is not a hide method so I guess
I'll have to tabpage.remove and tabpage.add at execution time.

On each tab-page I will have a datagrid (parent) and a couple of other
controls (radio buttons, labels, checkboxes, etc). Below the
tab-control will be a datagrid showing related data (child info) for
the selected

parent-row in the selected tab-page above it.

I'm in a quandry on how to set this up.

I can set up tab-page 1 and copy it to the other seven pages at design
time. How do I do it at run time since I'm changing the number of
tab-pages to display?

I seem to remember there was a way to have the same controls on each
page (without duplication - eg; having only one datagrid (just
changing to a different query string of the data set for each
tab-page) and visible on each tab-page). Surely I dont have to setup
8 datagrids, do I?

The data for the parent datagrid on each tab-page comes from the same
table (just different records based on category).

If I have to add and remove tab-pages at run-time, how do I easily
position all controls on that page?

I hope I've made this clear enough. Looking for recommendations,
references, code examples.

Thanks,

Hexman
 
M

Mick Doherty

If I understand correctly, you want one set of controls which will be common
to all tabpages.

One simple solution:
At Form Load() set up an ArrayList of the Controls on the First TabPage for
easy reference and in the TabControls SelectedIndexChanged() method reparent
these controls to the SelectedTabPage.

\\\
Private MyControls As ArrayList

Private Sub MainForm_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
MyControls = New ArrayList(TabPage1.Controls)
End Sub

Private Sub TabControl1_SelectedIndexChanged(ByVal sender As System.Object,
_
ByVal e As System.EventArgs) Handles
TabControl1.SelectedIndexChanged
If Not (TabControl1.Created) Then Return
For Each ctrl As Control In MyControls
TabControl1.SelectedTab.Controls.Add(ctrl)
Next
'Maybe call a custom RefreshDataGrid() method here
End Sub
///

Another Solution is to place the controls above the TabControl rather than
on a TabPage. This is more difficult to maintain at DesignTime as any
inadvertant dragging and dropping of the controls will result in them being
parented to the Tabpage. This would be the preffered method though as you
shouldn't get the flickering that you'll get with the first method.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top