Results 1 to 19 of 19

Thread: [2005] Working out Which controls are in which containers.

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2006
    Posts
    1,806

    [2005] Working out Which controls are in which containers.

    Hi,

    I know this is a CF question but it applies really to VS2005 design enviroment. I have panels in panels on top of panel etc. Is there anyway I can determine easily which controls are in which panels and which panels and in which main panels?

    Cheers,

    Jiggy!

    PS. I think I have confused my self on screen and don't know wether I have put the panels in the corrrect order.

  2. #2
    PowerPoster Deepak Sakpal's Avatar
    Join Date
    Mar 2002
    Location
    Mumbai, India
    Posts
    2,424

    Re: [2005] Working out Which controls are in which containers.

    I have hierarchy like this: Panel 1 -- Panel 2 -- Button1

    vb.net Code:
    1. Public Class Form1
    2.  
    3.     Private Sub Button1_Click( _
    4.         ByVal sender As System.Object, _
    5.         ByVal e As System.EventArgs _
    6.     ) Handles Button1.Click
    7.  
    8.         Dim parent1 As Panel
    9.         Dim parent2 As Panel
    10.  
    11.         parent1 = Button1.Parent
    12.         MessageBox.Show(parent1.Name) ' Will get u Panel 2
    13.  
    14.         parent2 = parent1.Parent
    15.         MessageBox.Show(parent2.Name) ' Will get u Panel 1
    16.     End Sub
    17.  
    18. End Class

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2006
    Posts
    1,806

    Re: [2005] Working out Which controls are in which containers.

    Thanks for that but I wanted to do it in vs2005 design. I have a textbox control somewhere in one of the panels and I cannot find it and need to either delete it or move it to the correct panel.

    Cheers,

    Jiggy!

  4. #4
    PowerPoster Deepak Sakpal's Avatar
    Join Date
    Mar 2002
    Location
    Mumbai, India
    Posts
    2,424

    Re: [2005] Working out Which controls are in which containers.

    oh...ok.. i misunderstood it. If you know the name of that control then select it from the drop down list of properties window. Once you select it from the list, that control will appear as selected in design view. You can then move it to somewhere else.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2006
    Posts
    1,806

    Re: [2005] Working out Which controls are in which containers.

    Thats the problem, it does not show up in the design window.

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2006
    Posts
    1,806

    Re: [2005] Working out Which controls are in which containers.

    I think it is in one of my panels behind something so can anyone please give me an example of how to step through each panel on my form and for each panel show all controls in the panel then I can trap for the control name txtNCNotes and see which panel it is in.

    Thanks for any help,

    Jiggy!

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Working out Which controls are in which containers.

    I'm not sure if it's available in a Mobile project but I'd guess that it is. Use the Document Outline window (Ctrl+Alt+T).
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2006
    Posts
    1,806

    Re: [2005] Working out Which controls are in which containers.

    Thank you mate, that is exactly what I want but it does not show the control I am looking for. Any ideas?

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Working out Which controls are in which containers.

    Every control is displayed in the Document Outline. If the one you want is not there then it doesn't exist. Perhaps your form has become corrupted. Have you tried opening the designer code file and examining the properties and parent of this control directly?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  10. #10
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: [2005] Working out Which controls are in which containers.

    I'm looking for an answer to that, too. Unfortunately, I am dealing with template generated code, which can be painfully annoying. The controls are created, but they don't show up in the Document Outline view, so they are probably retained as children to a parent control that no longer exists. This happened for me because I changed the name of the parent control, then re-generated the code. I can see where the controls are created, and their properties are set, but nobody owns them. The same situation seems to be true for your textbox, though without a template monkeying with your code, that shouldn't normally happen.
    My usual boring signature: Nothing

  11. #11

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2006
    Posts
    1,806

    Re: [2005] Working out Which controls are in which containers.

    This is wierd because I have done the following code in the form load and it does not find the control:-

    Code:
            Dim ctrlControls As Control
    
            For Each ctrlControls In Me.Controls
    
                If ctrlControls.Name.ToString = "txtNCNotes" Then
                    MessageBox.Show(panDepartments.Name.ToString)
                End If
    
            Next
    Any ideas or can someone tell me how I delete the control from my form without being able to select it.

    Cheers,

    Jiggy!

  12. #12

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2006
    Posts
    1,806

    Re: [2005] Working out Which controls are in which containers.

    It is in the .VB file as follows:-
    Code:
            'txtNCNotes
            '
            Me.txtNCNotes.Location = New System.Drawing.Point(64, 29)
            Me.txtNCNotes.Multiline = True
            Me.txtNCNotes.Name = "txtNCNotes"
            Me.txtNCNotes.Size = New System.Drawing.Size(161, 48)
            Me.txtNCNotes.TabIndex = 5
            Me.txtNCNotes.TabStop = False

  13. #13

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2006
    Posts
    1,806

    Re: [2005] Working out Which controls are in which containers.

    Can I just remove all instances of it from the .VB file to delete it and then start again?

  14. #14
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: [2005] Working out Which controls are in which containers.

    Yeah, that should work, since I end up doing it all the time with this template derived code. VS doesn't like you tinkering with that section, and sometimes it complains, but just deleting a control should raise no issues.
    My usual boring signature: Nothing

  15. #15

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2006
    Posts
    1,806

    Re: [2005] Working out Which controls are in which containers.

    Yeh I deleted it and renamed an existing textbox2 to txtNCNotes and it took hold of all the events and seems to work fine.

    Cheers All for your help,

    Jiggy!

  16. #16
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: [2005] Working out Which controls are in which containers.

    I'd like a better solution than that one, if anybody has one. In my case, I have lost the container for many controls (about a dozen). Deleting them and re-creating the whole lot is an option, but only a disturbingly temporary one.

    Therefore, if anybody knows how to find controls that are created, but are not displayed, and are child controls of non-existant parents (orphan controls, I suppose), I'd like to hear a solution.
    My usual boring signature: Nothing

  17. #17

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2006
    Posts
    1,806

    Re: [2005] Working out Which controls are in which containers.

    There must be a location where the relationship is setup and maybe those controls are still pointing to the deleted container. I will do some search myself. Would be good for the future to get a correct solution.

  18. #18
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: [2005] Working out Which controls are in which containers.

    I solved the problem, and here's the solution:

    If you look in the document outline (CTL+ALT+T), and the control is not there, then it either doesn't exist, or it was not added to the controls collection of the proper container control. If the control exists in the Property Manager list, then the first option is ruled out. Therefore, to fix the problem, all you need to do is go into the InitializeComponents sub and add in the line Me.<ContainerControl>.Controls.Add(<MissingControl>). This line gets added into the section where all the properties for the container controls are set, which is towards the bottom of the InitializeComponents Sub. You will see plenty of other examples nearby for most forms. Once the line has been added (using the right container for ContainerControl), then the control will appear correctly.

    Yes, this means editing the section of code that VS tells you NOT to edit, but I'm getting used to that by now.

    I'm such a rebel!
    My usual boring signature: Nothing

  19. #19

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2006
    Posts
    1,806

    Re: [2005] Working out Which controls are in which containers.

    Cheers for the reply mate; that makes sense I think!

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