Solved

How can I programmatically attach controls to a container?

Posted on 2001-07-10
20
221 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

733 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