all groups > dotnet windows forms databinding > july 2007 >
You're in the

dotnet windows forms databinding

group:

Readonly DataBinding Form


Readonly DataBinding Form Stefano Bonazzi
7/19/2007 12:00:00 AM
dotnet windows forms databinding: Hello, sorry for my english, i'm from Italy

I have the following scenario: a form with controls binded to a
bindingsource that is binded to a typed-dataset-table.

I must have the form (and the control) in a readonly mode to prevent
accidental write and allow modify after a keypress (F5).

Question: How can i handle with readonly non readonly status?

Is better setting the property for each control, using another binding
method or what else ?


Thank for your HELP

Stefano Bonazzi
Re: Readonly DataBinding Form Martin P
7/21/2007 3:33:22 AM
Hi stefano

I usually do this through locking all of the controls on the form
through a recursive function and then unlocking them when edit mode is
needed - one thing you should be aware of though is if you have any
combo boxes on your screen, they look really bad when they are
disabled so you may want to do things differenty.

Something like the following:


Public Sub LockControls(ByVal caller As Object, ByVal lock As
Boolean)
Dim ctl As Control
For Each ctl In (CType(caller, Control)).Controls
If ctl.HasChildren Then
LockControls(ctl, lock)
End If
If TypeOf ctl Is Windows.Forms.TextBox Or TypeOf ctl Is
Windows.Forms.ComboBox Then
ctl.Enabled = Not (lock)
ctl.BackColor = Color.White
End If
Next
End Sub
AddThis Social Bookmark Button