Toggle form from editable to readonly and vice versa

J

J. Clay

I know this has to be simple and I am missing something, but, I have a
windows forms application. The forms are bound to an object. I want to be
able to have the form open as readonly until an "Edit" button is pressed.
After all of the edits are done, they can then click an "End Edit" button to
lock to data again.

I am using VB.Net in VS 2005.

TIA,
Jim
 
R

rs

You many options:

You can disable all your input controls in a loop except for the edit
button. i.e.
(I am assuming your controls one directly painted on the form)

for each c as control in me.controls
if c.name = "Your edit botton name" then
c.enabled = true
else
c.enabled = false
end if

next

Other option is to paint the controls you want to disable on a panel
and disable the panel. Then you can disable all of them by:

p.enabled = false

There might be other solutions of course.
 
L

Linda Liu [MSFT]

Hi Jim,

Thank you for posting.

Would you tell me what you mean by "The forms are bound to an object"?

I think you could set the ReadOnly property of the controls(if they have
ReadOnly property) on your forms to true or just set the Enabled property
of the controls(except the "Edit" button) to false, so as to make the forms
readonly.

And vice versa, you could set ReadOnly property of the controls to false or
set the Enabled property of the controls to true to make the forms editable.

Hope this helps.


Sincerely,
Linda Liu
Microsoft Online Community Support

====================================================
When responding to posts,please "Reply to Group" via
your newsreader so that others may learn and benefit
from your issue.
====================================================
 
J

J. Clay

Linda,

For the form, I use databinding against a custom business object class that
implements the IEditable intrface. Looping through the controls would be
one option, but need to look into being able differentiate specific controls
that I want to be enabled or disable under specific circumstances. At this
point, I am looking at rs's solution of using panels and enabling/disabling
the panels.

Thanks,
Jim
 
L

Linda Liu [MSFT]

Hi Jim,

Thank you for your response.

Yes, you could put the controls on several panels on the form and
enable/disable the panels. It is an option.

You can also use databinding to enable/disable the controls on the form. I
mean that you could bind the ReadOnly or Enabled property of the controls
to a custom business object's field and then you could change the value of
this field in the custom business object to enable/disable the
corresponding controls.

The following is a sample.
public partial class Form1 : Form
{
private BusinessClass businessObj;
public Form1()
{
InitializeComponent();
businessObj = new BusinessClass();
this.textBox1.DataBindings.Add("ReadOnly", businessObj,
"ReadOnly");
this.textBox2.DataBindings.Add("ReadOnly", businessObj,
"ReadOnly");
businessObj.ReadOnly = true;
}
}
public class BusinessClass
{
private bool _ReadOnly = true;
public bool ReadOnly
{
get { return _ReadOnly; }
set { _ReadOnly = value; }
}
}

Hope this is helpful to you.
If you have any other concerns or need anything else, please don't hesitate
to let me know.



Sincerely,
Linda Liu
Microsoft Online Community Support

====================================================
When responding to posts,please "Reply to Group" via
your newsreader so that others may learn and benefit
from your issue.
====================================================
 

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