Results 1 to 8 of 8

Thread: Controls & Child Controls

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2000
    Location
    Europe, Lithuania
    Posts
    309

    Controls & Child Controls

    Hey,

    I have Control, which may have child controls. These child controls can have other child controls and so on.

    How to find parent control of specified child control?

    Findcontrol() doesn't search for child controls.

    Regards in advance

  2. #2
    Fanatic Member
    Join Date
    May 2002
    Posts
    746

    Re: Controls & Child Controls

    Originally posted by Norkis
    How to find parent control of specified child control?
    .Parent

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2000
    Location
    Europe, Lithuania
    Posts
    309
    Yes, I know that, but how to find that control if it is child control in another child control etc.?

  4. #4
    Fanatic Member
    Join Date
    May 2002
    Posts
    746
    Presumably you would know what the ultimate parent control is - like your form. Do a loop on parent until you get to the form name.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2000
    Location
    Europe, Lithuania
    Posts
    309
    Can you give sample of doing this?

  6. #6
    Fanatic Member
    Join Date
    May 2002
    Posts
    746
    Code:
    private void FindParents(object sender)
    {
    	// cast control of interest to generic control object
    	Control ctl=(Control)sender;
    	// loop until the parent control == form name (or whatever ultimate parent control you're interested in
    	while(ctl.Parent.Name!=this.Name)
    		{
    			System.Diagnostics.Trace.WriteLine(ctl.Parent.Name.ToString());
    			// make the current control the parent of the last tested control
    			ctl=ctl.Parent;
    		}
    }

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2000
    Location
    Europe, Lithuania
    Posts
    309
    I tryied to convert this code to vb at http://www.developerfusion.com/utili...tocsharp.aspx, but I got error An error occured while processing your code: -- line 2 col 14: invalid VariableDeclarator.

    What's the problem?

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2000
    Location
    Europe, Lithuania
    Posts
    309
    Your functions finds all parent controls if child control is specified.
    But how to find child control if I only know the main parent control?

    Like I said I have control, which has child controls, and those child controls have their child controls and so on.

    How to find child control if I only know main control's name, which is holding other controls?

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