check if a control is input control

P

parez

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
 
P

parez

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.
 
P

Pavel Minaev

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.
 
B

Bjørn Brox

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.
 
P

parez

parez skrev:








Use the "is" statement to test the type in your loop, and remember to
recursively process panels.

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..
 
A

.\\\\axxx

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!
 
P

parez

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top