Blocca Controlli da Inserimento e Modifica






Sub BloccaModificaReadOnly(ByVal parent As Control, ByVal Blocca As Boolean)

' True blocca i controlli scrittura = ReadOnly

' False Sblocca i controlli per poterci scrivere


'Dim Num As Long = 0

Dim Txt As TextBox
Dim Cmb As ComboBox
Dim Chec As CheckBox
Dim RadB As RadioButton

For Each c As Control In parent.Controls
'Debug.WriteLine(String.Format("{0} ({1})", c.Name, c.Parent.Name))


If TypeOf c Is TextBox And c.Name <> "TxtRicerca" Then
Txt = c
Txt.ReadOnly = Blocca
ElseIf TypeOf c Is ComboBox And c.Name <> "ComboRicerca" Then
Cmb = c
If Blocca = True Then
Cmb.DropDownStyle = ComboBoxStyle.Simple
Else
Cmb.DropDownStyle = ComboBoxStyle.DropDownList
End If
ElseIf TypeOf c Is CheckBox Then
Chec = c
Chec.Enabled = Not Blocca
ElseIf TypeOf c Is RadioButton Then
RadB = c
RadB.Enabled = Not Blocca
End If
'ListBox1.Items.Add(Num & " " & c.Name & " - " & c.Parent.Name)

'Num = Num + 1


If c.Controls.Count > 0 Then
BloccaModificaReadOnly(c, Blocca)
End If
Next

ComboBox3.DropDownStyle = ComboBoxStyle.DropDownList


'********************************************************

' Questa funzione sblocca i controlli in caso di Modifica

' e li blocca in fase di visualizzazione

'********************************************************

'If Blocco = False Then

' TextBox0.ReadOnly = False

' TextBox1.ReadOnly = False

' TextBox2.ReadOnly = False

' TextBox3.ReadOnly = False

' TextBox4.ReadOnly = False

' TextBox5.ReadOnly = False

' TextBox6.ReadOnly = False

' TextBox7.ReadOnly = False

' TextBox8.ReadOnly = False

' TextBox9.ReadOnly = False

' TextBox10.ReadOnly = False

' TextBox11.ReadOnly = False

' TextBox12.ReadOnly = False

' TextBox13.ReadOnly = False

' TextBox14.ReadOnly = False

' CheckAttivo.Enabled = True

'ElseIf Blocco = True Then

' CheckAttivo.Enabled = False

' TextBox0.ReadOnly = True

' TextBox1.ReadOnly = True

' TextBox2.ReadOnly = True

' TextBox3.ReadOnly = True

' TextBox4.ReadOnly = True

' TextBox5.ReadOnly = True

' TextBox6.ReadOnly = True

' TextBox7.ReadOnly = True

' TextBox8.ReadOnly = True

' TextBox9.ReadOnly = True

' TextBox10.ReadOnly = True

' TextBox11.ReadOnly = True

' TextBox12.ReadOnly = True

' TextBox13.ReadOnly = True

' TextBox14.ReadOnly = True

'End If

End Sub










( bloccacontrollidainserimentoemodifica.html )- by Paolo Puglisi - Modifica del 17/12/2023