check if a control is input control

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

    check if a control is input control


    Is there anyway i can find out if a control is an input control
    (textbox,radiob utton,checkbox, dropdown etc)
    and not a panel,group box etc.

    I am trying to implement "You have unsaved data on the form.Would you
    like to save it?" functionality.
    I created a SaveState method in my base form which adds all textboxes
    to a dictionary with their values.
    This method is called when the use saves the form or loads data.

    In the FormClosing event, I check the dictionary for changes in the
    text boxes and display a modal window if needed.


    This works great.Now I want to extend this functionality for all
    controls(input controls).

    Should i hardcode all the controls that i am using in my application
    and check the appropritate propery(.Text, .Checked) or is there any
    other way?


    TIA
  • parez

    #2
    Re: check if a control is input control

    On Jun 18, 3:29 pm, parez <psaw...@gmail. comwrote:
    Is there anyway i can find out if a control is an input control
    (textbox,radiob utton,checkbox, dropdown etc)
    and not a panel,group box etc.
    >
    I am trying to implement "You have unsaved data on the form.Would you
    like to save it?" functionality.
    I created a SaveState method in my base form which adds all textboxes
    to a dictionary with their values.
    This method is called when the use saves the form or loads data.
    >
    In the FormClosing event, I check the dictionary for changes in the
    text boxes and display a modal window if needed.
    >
    This works great.Now I want to extend this functionality for all
    controls(input controls).
    >
    Should i hardcode all the controls that i am using in my application
    and check the appropritate propery(.Text, .Checked) or is there any
    other way?
    >
    TIA
    When i writing the "Should i hardcode all the" line, i realised i
    might have to hardcode few types. But i still want the question to
    be answered.
    Also i can store the hashcodes instead of storing the values.

    Comment

    • Pavel Minaev

      #3
      Re: check if a control is input control

      On Jun 18, 11:29 pm, parez <psaw...@gmail. comwrote:
      Is there anyway i can find out if a control is an input control
      (textbox,radiob utton,checkbox, dropdown etc)
      and not a panel,group box etc.
      >
      I am trying to implement "You have unsaved data on the form.Would you
      like to save it?"  functionality.
      I created a SaveState method in my base form  which adds all textboxes
      to a dictionary with their values.
      This method is called when the use saves the form or loads data.
      >
      In the FormClosing event, I check the dictionary for changes in the
      text boxes and display a modal window if needed.
      >
      This works great.Now I want to extend this functionality for all
      controls(input controls).
      >
      Should i hardcode all the controls that i am using in my application
      and check the appropritate propery(.Text, .Checked) or is there any
      other way?
      There is no general straightforward way to do that, but there are a
      few tricks.

      If you use data binding for your controls, then you can assume that
      any control with bindings that have Binding.DataSou rceUpdateMode not
      equal to DataSourceUpdat eMode.Never is an input control.

      Alternatively, you might still want some finer distinction between
      input and non-input controls than their class. Tag property may be
      used to store a flag, for example, but that would have to be set
      manually.

      Comment

      • =?ISO-8859-1?Q?Bj=F8rn_Brox?=

        #4
        Re: check if a control is input control

        parez skrev:
        Is there anyway i can find out if a control is an input control
        (textbox,radiob utton,checkbox, dropdown etc)
        and not a panel,group box etc.
        >
        I am trying to implement "You have unsaved data on the form.Would you
        like to save it?" functionality.
        I created a SaveState method in my base form which adds all textboxes
        to a dictionary with their values.
        This method is called when the use saves the form or loads data.
        >
        In the FormClosing event, I check the dictionary for changes in the
        text boxes and display a modal window if needed.
        >
        >
        This works great.Now I want to extend this functionality for all
        controls(input controls).
        >
        Should i hardcode all the controls that i am using in my application
        and check the appropritate propery(.Text, .Checked) or is there any
        other way?
        >
        Use the "is" statement to test the type in your loop, and remember to
        recursively process panels.

        --
        Bjørn Brox

        Comment

        • parez

          #5
          Re: check if a control is input control

          On Jun 19, 11:42 am, Bjørn Brox <bpb...@gmail.c omwrote:
          parez skrev:
          >
          >
          >
          Is there anyway i can find out if a control is an input control
          (textbox,radiob utton,checkbox, dropdown etc)
          and not a panel,group box etc.
          >
          I am trying to implement "You have unsaved data on the form.Would you
          like to save it?" functionality.
          I created a SaveState method in my base form which adds all textboxes
          to a dictionary with their values.
          This method is called when the use saves the form or loads data.
          >
          In the FormClosing event, I check the dictionary for changes in the
          text boxes and display a modal window if needed.
          >
          This works great.Now I want to extend this functionality for all
          controls(input controls).
          >
          Should i hardcode all the controls that i am using in my application
          and check the appropritate propery(.Text, .Checked) or is there any
          other way?
          >
          Use the "is" statement to test the type in your loop, and remember to
          recursively process panels.
          >
          --
          Bjørn Brox
          I have a function that returns a list<somecontro l that gives me all
          somecontrols (recursively) on the form and i loop thru that. And i am
          using "is"
          Thanks..

          Comment

          • .\\\\axxx

            #6
            Re: check if a control is input control

            On Jun 19, 5:29 am, parez <psaw...@gmail. comwrote:
            Is there anyway i can find out if a control is an input control
            (textbox,radiob utton,checkbox, dropdown etc)
            and not a panel,group box etc.
            >
            I am trying to implement "You have unsaved data on the form.Would you
            like to save it?"  functionality.
            I created a SaveState method in my base form  which adds all textboxes
            to a dictionary with their values.
            This method is called when the use saves the form or loads data.
            >
            In the FormClosing event, I check the dictionary for changes in the
            text boxes and display a modal window if needed.
            >
            This works great.Now I want to extend this functionality for all
            controls(input controls).
            >
            Should i hardcode all the controls that i am using in my application
            and check the appropritate propery(.Text, .Checked) or is there any
            other way?
            >
            TIA
            On every project I always subclass all controls - even when I don't
            add any functionalty. That way, if I want to do somehting like this I
            can add a property (via an interface probably), say bool
            IsInputControl or even bool RequiresWarning OnChange. With this, you
            can now iterate your collection of controls, and check the property
            (for those that implement the interface) and only process if it is
            true.

            It helps in the long run, because there's _always_ going to be an
            exception that is a textbox you _don't_ want to warn about before
            closing!

            Comment

            • parez

              #7
              Re: check if a control is input control

              On Jun 19, 9:49 pm, ".\\\\axxx" <mailma...@gmai l.comwrote:
              On Jun 19, 5:29 am, parez <psaw...@gmail. comwrote:
              >
              >
              >
              Is there anyway i can find out if a control is an input control
              (textbox,radiob utton,checkbox, dropdown etc)
              and not a panel,group box etc.
              >
              I am trying to implement "You have unsaved data on the form.Would you
              like to save it?" functionality.
              I created a SaveState method in my base form which adds all textboxes
              to a dictionary with their values.
              This method is called when the use saves the form or loads data.
              >
              In the FormClosing event, I check the dictionary for changes in the
              text boxes and display a modal window if needed.
              >
              This works great.Now I want to extend this functionality for all
              controls(input controls).
              >
              Should i hardcode all the controls that i am using in my application
              and check the appropritate propery(.Text, .Checked) or is there any
              other way?
              >
              TIA
              >
              On every project I always subclass all controls - even when I don't
              add any functionalty. That way, if I want to do somehting like this I
              can add a property (via an interface probably), say bool
              IsInputControl or even bool RequiresWarning OnChange. With this, you
              can now iterate your collection of controls, and check the property
              (for those that implement the interface) and only process if it is
              true.
              >
              It helps in the long run, because there's _always_ going to be an
              exception that is a textbox you _don't_ want to warn about before
              closing!
              That sounds like a great idea(sub classing all controls) and the
              interface would have been great.I didnt have to wait too long to see
              the need for "RequiresWarnin gOnChnage". Its too late for me to do
              that. I have few days left on this project.
              I am storing a llist of controls that dont need to be checked .Thats
              how i get away.

              Comment

              Working...