Solved

How can I programmatically attach controls to a container?

Posted on 2001-07-10
20
220 Views
Last Modified: 2012-08-13
I want to be able to attach controls to a container, like a frame or a tab control, at run time.

For instance, if I have a control array of command buttons, I can load or unload more or less buttons. I'd like to be able to attach those buttons to a frame or tab control at run time.

Is it possible?
0
Comment
Question by:chaos_59
  • 6
  • 5
  • 4
  • +3
20 Comments
 
LVL 6

Accepted Solution

by:
JonFish85 earned 200 total points
ID: 6271559
try this:

Set ControlName.Container = FrameName
0
 
LVL 9

Expert Comment

by:Valliappan AN
ID: 6271782
I dont think, you could change the Container property. It is read-only, if I am right.

If you wish to attach to a frame, you could create the control in frame or tab control in design time, and then create the control arrays.

Could I know why you wish to do so, anyhow?

Cheers
0
 
LVL 8

Expert Comment

by:glass_cookie
ID: 6271909
I agree with valli_an : )

By the way, do remember to create the controls with an index of 0.

That's it!

glass cookie : )
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 6

Expert Comment

by:JonFish85
ID: 6271915
the Container property can be set as far as I am aware. I have used it before and it worked ok for me!
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 6272012
I agree with JonFish: you can set the container property at runtime (but no the parent Property)

0
 
LVL 9

Expert Comment

by:Valliappan AN
ID: 6272108
ok, got it. I too agree with you. Just now, found in MS site.

Look at this link:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vb98/html/vbprostandardcontainerx.asp

But in MSDN, library, i dont know why, it is put Container property returns the container name, in one place. In another place it is put it returns/sets. But the search value is "Container Property" in both. :>

Cheers.
0
 
LVL 9

Expert Comment

by:Valliappan AN
ID: 6272112
I tried with textbox, and with textbox control array, it works. :)
0
 
LVL 6

Expert Comment

by:JonFish85
ID: 6273315
the Container property can be set as far as I am aware. I have used it before and it worked ok for me!
0
 
LVL 6

Expert Comment

by:JonFish85
ID: 6273321
hmm sorry bout that. I did the unforgivable - refreshed :-(
0
 

Expert Comment

by:DavidLester
ID: 6274378
You can use the forms controls collection to add controls dynamically at run time.  For example if you wanted to add a textbox at runtime dynamically to a frame control name "Frame1" use the following code.

'========================================================
Private m_TextBox As TextBox ' Reference created textbox

Private Sub Form_Load()    
    ' Create the control and set its parent to Frame1.
    Set m_TextBox = Me.Controls.Add("vb.Textbox", "m_textbox", Frame1)
    ' Ensure that the new text box is visible.
    m_TextBox.Visible = True
End Sub
0
 
LVL 6

Expert Comment

by:JonFish85
ID: 6274402
DavidLester:

welcome to EE! It is common courtesy here to only comment on questions, rather than proposing an answer. Proposing an answer locks the question, and moves it to the "Answered Questions" section. You should not post "as answer" unless you are 300% sure your answer is 1) correct and 2) unique from what other users have commented. Please read the "Tips on comments and answers" at the bottom of this page.

I look forward to seeing you around EE!

To chaos_59:
Please reject the proposed answer and select a more appropriate one from the other comments...
0
 

Expert Comment

by:DavidLester
ID: 6274625
JonFish85

My answer does exactly want chaos_59 has required.
Also I don't think you should tell him what he should/shouln't except, who else does what he wants but him.

However, your point on "comments as opposed to answers" is gracefully taken.


David Lester
0
 
LVL 6

Expert Comment

by:JonFish85
ID: 6274639
yes, your answer has done what is required, but so does mine, no? I apologize for the comment about rejecting/accepting answers, and will be more careful in the future!
0
 
LVL 1

Author Comment

by:chaos_59
ID: 6275353
My appologies, I should have been more specific.
I am trying to add controls to a tabbed dialog control (SSTAB). 1 control for each tab.
I can control the number of tabs during run time. But I can't figure out how to add controls to each tab at run time.
I tried your suggestions, and although it adds the command buttons to the tab control, they are not placed on individual tabs. They are all placed on tab1.

This is the code that I am using.
Private Sub Form_Load()
SSTab1.Tabs = 27
SSTab1.TabsPerRow = 9

For x = 1 To SSTab1.Tabs - 1
    Load command1(x)   'load control
    command1(x).Visible = True
    SSTab1.Tab = x     'set current tab
    Set command1(x).Container = SSTab1
Next
End Sub
0
 
LVL 1

Author Comment

by:chaos_59
ID: 6275354
My appologies, I should have been more specific.
I am trying to add controls to a tabbed dialog control (SSTAB). 1 control for each tab.
I can control the number of tabs during run time. But I can't figure out how to add controls to each tab at run time.
I tried your suggestions, and although it adds the command buttons to the tab control, they are not placed on individual tabs. They are all placed on tab1.

This is the code that I am using.
Private Sub Form_Load()
SSTab1.Tabs = 27
SSTab1.TabsPerRow = 9

For x = 1 To SSTab1.Tabs - 1
    Load command1(x)   'load control
    command1(x).Visible = True
    SSTab1.Tab = x     'set current tab
    Set command1(x).Container = SSTab1
Next
End Sub
0
 
LVL 1

Author Comment

by:chaos_59
ID: 6275355
My appologies, I should have been more specific.
I am trying to add controls to a tabbed dialog control (SSTAB). 1 control for each tab.
I can control the number of tabs during run time. But I can't figure out how to add controls to each tab at run time.
I tried your suggestions, and although it adds the command buttons to the tab control, they are not placed on individual tabs. They are all placed on tab1.

This is the code that I am using.
Private Sub Form_Load()
SSTab1.Tabs = 27
SSTab1.TabsPerRow = 9

For x = 1 To SSTab1.Tabs - 1
    Load command1(x)   'load control
    command1(x).Visible = True
    SSTab1.Tab = x     'set current tab
    Set command1(x).Container = SSTab1
Next
End Sub
0
 
LVL 9

Expert Comment

by:Valliappan AN
ID: 6276538
how about adding a frame in each tab, and changing the container to that frame?
0
 

Expert Comment

by:DavidLester
ID: 6278208
I suggest you use my previous answer to add the controls to the tab control. Or as valli an suggested add the contols to a frame in each tab and then show/hide the frames depending on the visible tab.

WHAT MORE DO YOU WANT.
0
 
LVL 1

Author Comment

by:chaos_59
ID: 6281583
Valli an,
the problem with this solution is that it requires a preset upper limit and requires having all tabs, frames and controls to be loaded first at design time. I want to be able to add and remove tabs and load and unload controls as needed. For example, if I add a tab at run time, I want to load the controls for it, and have them placed on the new tab.

DavidLester,
I won't accept your answer because it essentially does the same thing as JonFish85's answer. If I am going to accept an incomplete answer the points will go to the first person that gives that answer.
WHAT MORE DO I WANT? I want an answer to my question!
0
 
LVL 1

Author Comment

by:chaos_59
ID: 6281603
It seems that I need to be more precise with my question. And in fairness JonFish85 answered this question correctly first. I'll post a new, more precise, question later. Hopefully someone can give me an answer that does what I want.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question