#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    27
    Rep Power
    0

    C#: determining type of control


    i'm a new to this thing, so please be gentle. and thanks in advance.. hehe... how do i do this? let's say i have controls in the group box and i want to determine whether the control is a textbox or not... if so, clear it....

    psuedo code...

    - foreach(control c in groupbox.controls)
    - if c is textbox, c.text=string.empty

    thanx again...

    --ayan
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    27
    Rep Power
    0
    hello there... hehe... the answer is just the "is" word...
    PHP Code:
    foreach(Control c in groupBox1.Controls){
      if(
    c is TextBoxc.Text=string.Empty;

  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    1
    Rep Power
    0
    One line dude:

    foreach (var c in panel.Controls.OfType<TextBox>()) c.Text = string.Empty;
  6. #4
  7. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    5
    Rep Power
    0
    Simply use riveting and rivetingly simple! Method.It even works from Control Arrays and can be called from events other than GotFocus such as Change and Keydown...
    dapfor.com/en/net-suite/net-grid/tutorial/data-types

IMN logo majestic logo threadwatch logo seochat tools logo