Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

lock form fields with lock bit 1

Status
Not open for further replies.

Saturn57

Programmer
Aug 30, 2007
275
CA
I'm looking for the most efficient way to lock a record set on a form once the record has been approved. I want to still be able to see the fields on the form but I want to stop them from being edited once the lock bit has been set on the record. Any hints would be appreciated. Thanks in advance
 
just change the textfield property to ReadOnly.
Code:
textbox1.ReadOnly = true;
This will stop the control being edited, but still allow the user to see the contents of the control.

If any more help is needed, give a shout!

Regards,

Martin

Computing Design And Services:
 
I have many fields on this form. Is there a quickway to get this achieved instead of one text box at a time?
 
I have a user control with a property EditMode which I can set in run time.

Here is a code I'm using to set this property for my controls (in a static global class)

Code:
    /// <summary>
    /// Sets enabled property of the passed controls
    /// </summary>
    /// <param name="cc"></param>
    /// <param name="enabled"></param>
    public static void SetEnabled(ControlCollection cc, bool enabled)
    {
        foreach (Control control in cc)
        {
            if (control is TextBox && control.ID != null)
                ((TextBox)control).ReadOnly = !enabled;
            if (control is DropDownList && control.ID != null)
                ((DropDownList)control).Enabled = enabled;
            if (control is CheckBox && control.ID != null)
                ((CheckBox)control).Enabled = enabled;

            if (control is RequiredFieldValidator && control.ID != null)
            {
                if (((RequiredFieldValidator)control).Enabled == true) // don't change if it is already false
                {
                    ((RequiredFieldValidator)control).Enabled = enabled;
                }
                if (enabled = false)
                   ((RequiredFieldValidator)control).Visible = false;

            }
            if (control is RegularExpressionValidator  && control.ID != null)
            {
                if (((RegularExpressionValidator)control).Enabled == true)
                {
                    ((RegularExpressionValidator)control).Enabled = enabled;
                }
                if (enabled == false)
                   ((RegularExpressionValidator)control).Visible = false;   
            }

            if (control.Controls.Count > 0)
            {
                clseditmode.SetEnabled(control.Controls, enabled);
            }
        }
    }


My user controls have this custom property
Code:
/// <summary>The EditMode property is responsible for the Enabled style of the controls</summary>
    ///
   
    private bool editMode ;
    [Description("The EditMode property is responsible for the Enabled style of the controls"), DefaultValue(true), Category("User-Defined")]  
    public bool EditMode
    {
        get { return editMode ; }
        set {
            this.editMode = value;
            clseditmode.SetEnabled(this.Controls, value);
        }
    }

clseditmode is a global static class.

I'm using it in ASP.NET user controls, I think the idea for WinForms would be similar.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top