Bonjour,
Je n'aime pas cette fonction que je n'arrive pas à améliorer pouvez vous me donner un conseil ou deux pour l'optimiser svp ? Je ne maitrise surement pas tout et je serai curieux de voir comment la simplifier ...

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
''' <summary>
    ''' Return True si au moins un champs obligatoire n'est pas rempli, et le colore
    ''' </summary>
    ''' <param name="lstchamps"></param>
    ''' <returns></returns>
    ''' <remarks>ED et AK 24/06/2009</remarks>
    Public Function ChampsObligatoireIsVide(ByRef lstchamps As Generic.List(Of Control)) As Boolean
        Dim bChampsVide As Boolean = False
        For Each CurControl In lstchamps
            If (TypeOf CurControl Is TextBox) Then
                Dim tempcontrol As TextBox
                tempcontrol = (CType(CurControl, TextBox))
                If tempcontrol.Text = "" Then
                    tempcontrol.BackColor = Color.Orange
                    bChampsVide = True
                Else
                    tempcontrol.BackColor = Color.NavajoWhite
                End If
            ElseIf (TypeOf CurControl Is ComboBox) Then
                Dim tempcontrol As ComboBox
                tempcontrol = (CType(CurControl, ComboBox))
                If (Trim(tempcontrol.Text) = "") Or (tempcontrol.SelectedValue Is Nothing) Then
                    tempcontrol.BackColor = Color.Orange
                    bChampsVide = True
                Else
                    tempcontrol.BackColor = Color.NavajoWhite
                End If
 
            ElseIf (TypeOf CurControl Is DateTimePicker) Then
                Dim tempcontrol As DateTimePicker
                tempcontrol = (CType(CurControl, DateTimePicker))
                If Not IsDate(tempcontrol.Text) Then
                    tempcontrol.BackColor = Color.Orange
                    bChampsVide = True
                Else
                    tempcontrol.BackColor = Color.NavajoWhite
                End If
            ElseIf (TypeOf CurControl Is CheckBox) Then
                Dim tempcontrol As CheckBox
                tempcontrol = (CType(CurControl, CheckBox))
                If tempcontrol.Checked = False Then
                    tempcontrol.BackColor = Color.Orange
                    bChampsVide = True
                Else
                    tempcontrol.BackColor = Color.NavajoWhite
                End If
            ElseIf (TypeOf CurControl Is PADatePicker) Then
                Dim tempcontrol As PADatePicker
                tempcontrol = (CType(CurControl, PADatePicker))
                If (tempcontrol.Text = " / /    ") Or (Not IsDate(tempcontrol.Text)) Then
                    tempcontrol.BackColor = Color.Orange
                    bChampsVide = True
                Else
                    tempcontrol.BackColor = Color.NavajoWhite
                End If
            End If
 
        Next
        Return bChampsVide
    End Function
et dans le meme genre j'ai ca aussi :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
 
    Public Sub EditablePanelAptFormGeneral(ByVal valueTrueOrFalse As Boolean)
  Dim c() As Control = {Me.Panel1, Me.Panel3, Me.Panel4, Me.pnlWPrices, Me.pnlMPrices, Me.TabST, Me.TabVST} 'Me.Panel24, Me.Panel26, Me.pnlWPrices1, Me.pnlNPrices, Me.pnlMPrices1
        Dim LstTempcontrol As New Generic.List(Of ComboBox)
        For Each i As Control In c
            For Each CurControl As Control In i.Controls
                If (TypeOf CurControl Is TextBox) Then
                    Dim tempcontrol As TextBox
                    tempcontrol = (CType(CurControl, TextBox))
                    tempcontrol.ReadOnly = Not valueTrueOrFalse
 
                ElseIf (TypeOf CurControl Is CheckBox) Then
                    Dim tempcontrol As CheckBox
                    tempcontrol = (CType(CurControl, CheckBox))
                    tempcontrol.AutoCheck = valueTrueOrFalse
 
                ElseIf (TypeOf CurControl Is ComboBox) Then
                    Dim tempcontrol As ComboBox
                    tempcontrol = (CType(CurControl, ComboBox))
                    ' tempcontrol.Enabled = valueTrueOrFalse
                    If Not valueTrueOrFalse Then
                        If tempcontrol.DropDownStyle = ComboBoxStyle.DropDownList Then 'Test si le combobox est a DropDownList
                            tempcontrol.DropDownStyle = ComboBoxStyle.DropDown 'passer le combobox au style DropDown
                            SetComboReadOnly(tempcontrol, Not valueTrueOrFalse)
                            LstTempcontrol.Add(tempcontrol) 'Construire une lise des combobox qui ont un style DropDownList
                        Else
                            SetComboReadOnly(tempcontrol, Not valueTrueOrFalse)
                        End If
                    Else
                        For Each lst In LstTempcontrol 'parcourir la liste des combobox qui ont un style DropDownList
                            lst.DropDownStyle = ComboBoxStyle.DropDownList 'Remettre le style d'orgine des combobox
                        Next
                        SetComboReadOnly(tempcontrol, Not valueTrueOrFalse)
                    End If
                ElseIf (TypeOf CurControl Is RadioButton) Then
                    Dim tempcontrol As RadioButton
                    tempcontrol = (CType(CurControl, RadioButton))
                    tempcontrol.AutoCheck = valueTrueOrFalse
 
                ElseIf (TypeOf CurControl Is DateTimePicker) Then
                    Dim tempcontrol As DateTimePicker
                    tempcontrol = (CType(CurControl, DateTimePicker))
                    tempcontrol.Enabled = valueTrueOrFalse
                ElseIf (TypeOf CurControl Is PADatePicker) Then
                    Dim tempcontrol As PADatePicker
                    tempcontrol = (CType(CurControl, PADatePicker))
                    ' tempcontrol.Enabled = valueTrueOrFalse
                    tempcontrol.Read_Only = Not valueTrueOrFalse
                ElseIf (TypeOf CurControl Is Button) Then
                    Dim tempcontrol As Button
                    tempcontrol = (CType(CurControl, Button))
                    tempcontrol.Enabled = valueTrueOrFalse
 
                ElseIf (TypeOf CurControl Is DataGridView) Then
                    Dim tempcontrol As DataGridView
                    tempcontrol = (CType(CurControl, DataGridView))
                    tempcontrol.ReadOnly = Not valueTrueOrFalse
 
                ElseIf (TypeOf CurControl Is PictureBox) Then
                    Dim tempcontrol As PictureBox
                    tempcontrol = (CType(CurControl, PictureBox))
                    tempcontrol.Enabled = Not valueTrueOrFalse
 
                End If
            Next
        Next
end sub