Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / June 2006

Tip: Looking for answers? Try searching our database.

Toggle form from editable to readonly and vice versa

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
J. Clay - 25 May 2006 16:24 GMT

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
rs - 25 May 2006 17:03 GMT
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.
Linda Liu [MSFT] - 26 May 2006 03:09 GMT
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. Clay - 31 May 2006 15:56 GMT

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

> Hi Jim,
>
[quoted text clipped - 24 lines]
> from your issue.
> ====================================================
Linda Liu [MSFT] - 01 Jun 2006 03:07 GMT
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.
====================================================

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.