Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 238
  • Last Modified:

How can I programmatically attach controls to a container?

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
chaos_59
Asked:
chaos_59
  • 6
  • 5
  • 4
  • +3
1 Solution
 
JonFish85Commented:
try this:

Set ControlName.Container = FrameName
0
 
Valliappan ANSenior Tech ConsultantCommented:
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
 
glass_cookieCommented:
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
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
JonFish85Commented:
the Container property can be set as far as I am aware. I have used it before and it worked ok for me!
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
I agree with JonFish: you can set the container property at runtime (but no the parent Property)

0
 
Valliappan ANSenior Tech ConsultantCommented:
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
 
Valliappan ANSenior Tech ConsultantCommented:
I tried with textbox, and with textbox control array, it works. :)
0
 
JonFish85Commented:
the Container property can be set as far as I am aware. I have used it before and it worked ok for me!
0
 
JonFish85Commented:
hmm sorry bout that. I did the unforgivable - refreshed :-(
0
 
DavidLesterCommented:
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
 
JonFish85Commented:
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
 
DavidLesterCommented:
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
 
JonFish85Commented:
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
 
chaos_59Author Commented:
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
 
chaos_59Author Commented:
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
 
chaos_59Author Commented:
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
 
Valliappan ANSenior Tech ConsultantCommented:
how about adding a frame in each tab, and changing the container to that frame?
0
 
DavidLesterCommented:
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
 
chaos_59Author Commented:
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
 
chaos_59Author Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

  • 6
  • 5
  • 4
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now