Print Page | Close Window

TabControl.InsertItem

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Controls
Forum Description: Topics Related to Codejock Controls
URL: http://forum.codejock.com/forum_posts.asp?TID=10834
Printed Date: 30 November 2024 at 2:32pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: TabControl.InsertItem
Posted By: Jean
Subject: TabControl.InsertItem
Date Posted: 30 May 2008 at 3:54am
I like to dynamiccally fill a TabControl with items and TabPages.
On the pages I like to load Controls.
I use WinApi SetParent for this.

This is the Gui of my test application:


I can create the Items, Pages and Controls. If you switch the TabPages, everything looks fine
But if you click on a TextBox and then on the underlaying tabPage the TabControl is confused and doesen't show the page content proper.

Test:
1.) click the AddPage button twice
2.) select the second TabPage (new 1)
3.) click AddControl
4.) click inside the new control (the textbox)
5.) click below on the TabPage

I guess using SetParent causes the problem. Is there another way to create and draw the TabControl + Child-Controls dynamically?

uploads/20080530_035238_Sample.zip - uploads/20080530_035238_Sample.zip



Replies:
Posted By: Oleg
Date Posted: 30 May 2008 at 4:53am
Hello,
 
You can try avoid using  TabControlPage, just add new controls to form/tabcontol and show/hide them if user change selected tab
 
tabControl.InsertItem tabControl.ItemCount, "New " & tabControl.ItemCount, 0, 0
...
 
Call SetParent(dynTxt(dynTxt.Count - 1).hWnd, tabControl.hWnd)
 
 
 


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: Jean
Date Posted: 30 May 2008 at 5:47am
This seems to work. Thank you!
Now I have to write code to do what I thought the TabControl is doing.
But I guess the TabControl+TabControlPages have not been developped for my "special case".


Posted By: Krog
Date Posted: 04 November 2009 at 12:04am
Hi!

I would like to use the TabControlPage for the same purpose and I am getting the same problem.

I am using the following line instead of SetParent:

Set Text1(TxtCount).Container = TabControlPage1(TabCount)

How can I solve it?

Note: I don't want to do the TabControlPage work and also I want the TabControlPage background that we don't get using a frame or picturebox... And the TabControlPages may be created at runtime.

Can someone help me?


-------------
Product: Xtreme SuitePro (ActiveX) version 15.2.1
Platform: Windows XP SP2
Language: Visual Basic 6 SP6


Posted By: Krog
Date Posted: 04 November 2009 at 12:48am
I was testing a workaround using an array of TabControlPages using the Index property at design time but a bug occurs and no one control is displayed, and only one TabControlPage is displayed, empty.

The solution was:
-not to use the Index property at design time to create the array;
-use an array in the code and assign it at run-time, like this:

Dim TabCtlPage() As TabControlPage

Private Sub Form_Load()
Dim i As Integer

ReDim TabCtlPage(0 To 5)
Set TabCtlPage(0) = TabControlPage1
Set TabCtlPage(1) = TabControlPage2
Set TabCtlPage(2) = TabControlPage3
Set TabCtlPage(3) = TabControlPage4
Set TabCtlPage(4) = TabControlPage5
Set TabCtlPage(5) = TabControlPage6

' The tabs that are not being used, we hide:

TabControl1.Item(3).Visible = False
TabControl1.Item(4).Visible = False
TabControl1.Item(5).Visible = False

End Sub


But I am still preferring to create the TabControlPages at run-time and use an array. So the solution is welcome.


-------------
Product: Xtreme SuitePro (ActiveX) version 15.2.1
Platform: Windows XP SP2
Language: Visual Basic 6 SP6


Posted By: Xander75
Date Posted: 09 May 2010 at 4:08am
Hi Jean & Krog,

I stumbled across this post recently as I looked for an answer here in the forums, I know this is a bit late in the day from when you originally posted but I have found a solution and thought I should share it.

I too faced the issue with using the TabControlPage but I manged to find a solution that allows you to add new Tabs dynamically and any controls, in my case I was using the ReportControl.

The solution is to avoid using the TabControlPage and instead use a PictureBox as the container, I also avoid using the SetParent API. Please see the code below and the attached sample project for the solution.

Code Preview:

Dim lIndex As Long

Private Sub Command1_Click()
    ' Increment the lIndex variable
    lIndex = lIndex + 1
  
    ' Load a new picReport Container and rpcReport ReportControl
    Load picReport(lIndex)
    Load rpcReport(lIndex)
   
    ' Insert the picReport Container into a new tab
    tabReport.InsertItem lIndex, "New " & lIndex, picReport(lIndex).hWnd, 0
    tabReport.SelectedItem = lIndex
   
    ' Set the rpcReport ReportControl container to be the picReport Container
    Set rpcReport(lIndex).Container = picReport(lIndex)
   
    ' Resize the rpcReport ReportControl to fit the picReport Container
    rpcReport(lIndex).Move 0, 0, picReport(lIndex).Width, picReport(lIndex).Height
    rpcReport(lIndex).Visible = True
   
    ' Add Column Configs
    Dim Column As ReportColumn
    Set Column = rpcReport(lIndex).Columns.Add(0, "Name", 200, True)
   
    ' Add Data to Grid
    Dim Record As ReportRecord
    Set Record = rpcReport(lIndex).Records.Add
    Record.AddItem "Grid " & CStr(lIndex)
   
    ' Refresh the rpcReport ReportControl
    rpcReport(lIndex).Populate
End Sub

I hope this helps someone...

uploads/20100509_041040_DynamicTabs_.zip - uploads/20100509_041040_DynamicTabs_.zip


Posted By: Krog
Date Posted: 31 July 2016 at 3:49pm
Years later I was with the same problem and I found this thread with my own comments! I didn't even remember of them.

Well, I solved it using a Codejock GroupBox with Transparent=True (and removing the Caption and with no borders) on top of the TabControlPage

It works like a charm


-------------
Product: Xtreme SuitePro (ActiveX) version 15.2.1
Platform: Windows XP SP2
Language: Visual Basic 6 SP6



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net