how to find a control exist in the form?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nirmalsingh
    New Member
    • Sep 2006
    • 218

    how to find a control exist in the form?

    hai all i am generating list box dynamically in a form.

    Code:
     ListBox li = new ListBox();
                                 myForm.Controls.Add(li);
                                 li.Name ="SearchName";
                                 System.Drawing.Point Location = new Point(TextBoxTop-60,TextBoxLeft +30);
                                 System.Drawing.Size size = new Size(200, 72);
                                 li.BringToFront();
                                 li.Location = Location;
                                 li.Size = size;
                                 li.Visible = true;
    now before creating a list box , i want to verify that whether a listbox already exist in the form.
    thanx in advance
    Nirmal
  • DrBunchman
    Recognized Expert Contributor
    • Jan 2008
    • 979

    #2
    Unless you know the ID of the listbox you are looking for you'll need to loop through all the controls on the page and test each one to see if it's a listbox.

    Dr B

    Comment

    • Saravanan Krishnan
      New Member
      • Mar 2008
      • 11

      #3
      Form.ControlCol lection fc = new Form.ControlCol lection(form1);

      fc.Contains(url stbox);

      the above line will return true if your urlstbox control exsists in ur form or else it'll return false.

      hope it'll help u...

      regards...
      Saravanan Krishnan

      Comment

      Working...