Solved

How can I programmatically attach controls to a container?

Posted on 2001-07-10
20
213 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
 
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 142

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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now