471,337 Members | 1,411 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,337 software developers and data experts.

check if a control is input control


Is there anyway i can find out if a control is an input control
(textbox,radiobutton,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
Jun 27 '08 #1
6 1701
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,radiobutton,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.
Jun 27 '08 #2
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,radiobutton,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.DataSourceUpdateMode not
equal to DataSourceUpdateMode.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.
Jun 27 '08 #3
parez skrev:
Is there anyway i can find out if a control is an input control
(textbox,radiobutton,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
Jun 27 '08 #4
On Jun 19, 11:42 am, Bjørn Brox <bpb...@gmail.comwrote:
parez skrev:
Is there anyway i can find out if a control is an input control
(textbox,radiobutton,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<somecontrol that gives me all
somecontrols (recursively) on the form and i loop thru that. And i am
using "is"
Thanks..
Jun 27 '08 #5
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,radiobutton,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 RequiresWarningOnChange. 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!
Jun 27 '08 #6
On Jun 19, 9:49 pm, ".\\\\axxx" <mailma...@gmail.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,radiobutton,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 RequiresWarningOnChange. 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 "RequiresWarningOnChnage". 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.
Jun 27 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Alain Dhaene | last post: by
2 posts views Thread by Nicolae Fieraru | last post: by
5 posts views Thread by A.Dagostino | last post: by
2 posts views Thread by limbo2u | last post: by
1 post views Thread by scprosportsman | last post: by
3 posts views Thread by student4lifer | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.