Control eunumeration

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • axapta

    Control eunumeration

    Hi,
    I need to check whether at least ONE control has been filled in prior to the
    user hitting a seacrh button. I have a series of textboxes and a couple of
    drop-down list boxes. I've seen in MS Access (yes I know old skool) where
    you can do a loop around the different types of controls by their controlid
    and check whether they are blank or not. Is there a similar sort of thing
    for .net.

    Any hints, most welcomed.

  • tommaso.gastaldi@uniroma1.it

    #2
    Re: Control eunumeration

    On 2 Giu, 21:09, "axapta" <jas.jac...@gma il.comwrote:
    Hi,
    I need to check whether at least ONE control has been filled in prior to the
    user hitting a seacrh button.  I have a series of textboxes and a coupleof
    drop-down list boxes.  I've seen in MS Access (yes I know old skool) where
    you can do a loop around the different types of controls by their controlid
    and check whether they are blank or not.  Is there a similar sort of thing
    for .net.
    >
    Any hints, most welcomed.

    You can loop on controls, forms or whatever. For instance:

    For Each c As Control In Me.Controls

    If TypeOf c Is TextBox Then
    ' ...
    End If

    Next c


    Depending on the case, you may also need recursion.


    Tommaso

    Comment

    • =?Utf-8?B?U3VydHVyWg==?=

      #3
      Re: Control eunumeration

      Tommaso is correct but note that if a textbox is inside a container (e.g.
      inside a GroupBox, Panel, TabControl etc) then it won't show up - you need
      to go through each container on the form.

      (This is what I think Tommaso meant when he mentioned recursion).

      --
      David Streeter
      Synchrotech Software
      Sydney Australia


      "tommaso.gastal di@uniroma1.it" wrote:
      On 2 Giu, 21:09, "axapta" <jas.jac...@gma il.comwrote:
      Hi,
      I need to check whether at least ONE control has been filled in prior to the
      user hitting a seacrh button. I have a series of textboxes and a couple of
      drop-down list boxes. I've seen in MS Access (yes I know old skool) where
      you can do a loop around the different types of controls by their controlid
      and check whether they are blank or not. Is there a similar sort of thing
      for .net.

      Any hints, most welcomed.
      >
      >
      You can loop on controls, forms or whatever. For instance:
      >
      For Each c As Control In Me.Controls
      >
      If TypeOf c Is TextBox Then
      ' ...
      End If
      >
      Next c
      >
      >
      Depending on the case, you may also need recursion.
      >
      >
      Tommaso
      >
      >

      Comment

      • Phill W.

        #4
        Re: Control eunumeration

        axapta wrote:
        I need to check whether at least ONE control has been filled in prior to
        the user hitting a seacrh button. I have a series of textboxes and a
        couple of drop-down list boxes. I've seen in MS Access (yes I know old
        skool) where you can do a loop around the different types of controls by
        their controlid and check whether they are blank or not. Is there a
        similar sort of thing for .net.
        Control Arrays.

        Yes, I really did mean to say that.

        Use an Array (or similar "list" construct) containing the Controls, in
        which you're interested, something like:

        Private m_EditControls as Control() = {}

        Sub Form_Load( ... ) Handles MyBase.Load

        ' Put all the controls you care about into the array
        m_EditControls = New Control() = _
        { Me.TextBox1 _
        , Me.TextBox2 _
        , Me.Combobox3 _
        }
        End Sub

        Then, at any point thereafter, you can test for any one of them being
        non-blank using something like :

        Function AnyValueEntered () as Boolean
        For Each ctl as Control in m_EditControls
        If ctl.Text <String.Empty Then
        Return True
        End If
        Return False
        Next
        End Function

        If you move into other controls where you have to check more than just
        the Text, you'll have to start down-casting to the correct type to get
        the right properties, as in:

        For Each ctl as Control in m_EditControls
        if Typeof ctl Is TextBox Then
        if ( DirectCast( ctl, TextBox ).Text <String.Empty Then
        Return True
        End If
        End If

        HTH,
        Phill W.

        Comment

        Working...