Results 1 to 8 of 8

Thread: How do I set the Container property of a control?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2011
    Location
    Palm Coast, FL
    Posts
    626

    How do I set the Container property of a control?

    Short version of the question:
    How do I set the Container property of a tB control (text box)?

    Context:
    I've got an array of tB text boxes which I create dynamically at runtime from a single initial textbox already on a form. The text boxes are within containers - frames to be exact. There's two different frames with some of the text boxes in the first frame and some in the second frame (meaning not all of the textboxes in the control array have the same container). I need to be able to set the container of the dynamically created text boxes so that they'll appear within the correct frame. But when I try to set the Container property of the new textbox, I get a 438 error (Object doesn't support this property or Method). How do I set this value?

    If I don't try to specify a Container, the new dynamically created text boxes appear in the first frame while I want them to appear in the second frame. So it appears that the assumption being made in the underlying code is that all elements of a control array will all share the same container. As my situation shows, that's not a correct assumption to make and should allow developer override.


    The code is pretty straightforward and works in VB6 so don't think it's a coding error:

    Code:
            ' Find the next index
            Dim NewIndex As Integer
            NewIndex = txtOrderDetail.UBound + 1
    
            
            ' Load the new text box
            Load txtOrderDetail(NewIndex)
            
            ' Set the container for the new control
              Set txtOrderDetail(NewIndex).Container = poContainer
            
            ' make it visible
            txtOrderDetail(NewIndex).Visible = True
    I've looked at the definition for the Container property and it seems to be read-only (there's a Get but no Set/Let)

    Code:
            Public Property Get Container() As Object
                On Error Resume Next
                EnsureFormIsLoaded()
                Return Me.RootWindowElementBase.Container
            End Property
    I've followed the definitions back to the WindowsControls.twin file, _WindowElement interface and there's only a Get Container so this seems to go all the way back to the element base class. This class is not editable or else I'd try to resolve this myself by adding a Set version of this.

    I believe this is an oversight or perhaps not and just hasn't been implemented yet?
    Last edited by AAraya; Jul 24th, 2024 at 12:22 PM.

  2. #2
    Addicted Member
    Join Date
    Dec 2020
    Posts
    227

    Re: How do I set the Container property of a control?

    Quote Originally Posted by AAraya View Post
    Short version of the question:
    How do I set the Container property of a tB control (text box)?

    Context:
    I've got an array of tB text boxes which I create dynamically at runtime from a single initial textbox already on a form. The text boxes are within containers - frames to be exact. There's two different frames with some of the text boxes in the first frame and some in the second frame (meaning not all of the textboxes in the control array have the same container). I need to be able to set the container of the dynamically created text boxes so that they'll appear within the correct frame. But when I try to set the Container property of the new textbox, I get a 438 error (Object doesn't support this property or Method). How do I set this value?

    The code is pretty straightforward and works in VB6 so don't think it's a coding error:

    Code:
            ' Find the next index
            Dim NewIndex As Integer
            NewIndex = txtOrderDetail.UBound + 1
    
            
            ' Load the new text box
            Load txtOrderDetail(NewIndex)
            
            ' Set the container for the new control
              Set txtOrderDetail(NewIndex).Container = poContainer
            
            ' make it visible
            txtOrderDetail(NewIndex).Visible = True
    I've looked at the definition for the Container property and it seems to be read-only (there's a Get but no Set/Let)

    Code:
            Public Property Get Container() As Object
                On Error Resume Next
                EnsureFormIsLoaded()
                Return Me.RootWindowElementBase.Container
            End Property
    I've followed the definitions back to the WindowsControls.twin file, _WindowElement interface and there's only a Get Container so this seems to go all the way back to the element base class. This class is not editable or else I'd try to resolve this myself by adding a Set version of this.

    I believe this is an oversight or perhaps not and just hasn't been implemented yet?
    Not implemented yet, sorry. @sokinkeso had mentioned it over on discord some time ago, so it is known, and we'll get to it soon.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2011
    Location
    Palm Coast, FL
    Posts
    626

    Re: How do I set the Container property of a control?

    OK, glad to know it's already been mentioned.

  4. #4
    PowerPoster
    Join Date
    Jan 2020
    Posts
    4,180

    Re: How do I set the Container property of a control?

    can use api,setparent

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2011
    Location
    Palm Coast, FL
    Posts
    626

    Re: How do I set the Container property of a control?

    Quote Originally Posted by xiaoyao View Post
    can use api,setparent

    [Edit] - Deleted as the info I posted was wrong!
    Last edited by AAraya; Jul 29th, 2024 at 10:18 AM.

  6. #6
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    6,182

    Re: How do I set the Container property of a control?

    VB6 (and tB) Frame controls have .hwnd

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2011
    Location
    Palm Coast, FL
    Posts
    626

    Re: How do I set the Container property of a control?

    [Deleted...]
    Last edited by AAraya; Aug 1st, 2024 at 09:08 AM.

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2011
    Location
    Palm Coast, FL
    Posts
    626

    Re: How do I set the Container property of a control?

    Too weird - now it works just fine with no error. Issue resolved - the controls now appear in the correct containers!

    Thanks xiaoyao and fafalone!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width