I am calling function (i don't know, if this code is really called function.. so please correct me if i'm wrong) to disable the fields except for buttons and other necessary information needed during form load. But my problem is, some fields are not disabled. My application goes like this: During form load, i should select first process to enable certain input fields. Process determines which fields should be enabled and disabled. As long as I have not selected any process, all input fields should be disabled. Can you check the code I used? What seems to be the problem..
Thank you.

**DISABLE FUNCTION -- **

Private Sub DisableAll()
        Dim c As Control
        For Each c In Me.Controls
            If TypeOf c Is Control Then
                c.Enabled = False
            End If
            If TypeOf c Is ComboBox Then
                If c.Name = "cmbProcess" Then
                    CType(c, ComboBox).Enabled = True
                End If
                If c.Name = "cmbLineNo" Then
                    CType(c, ComboBox).Enabled = False
                End If
            End If
            If TypeOf c Is Button Then
                If c.Name = "btnSave" Then
                    CType(c, Button).Enabled = True
                End If
                If c.Name = "btnEdit" Then
                    CType(c, Button).Enabled = True
                End If
                If c.Name = "btnDelete" Then
                    CType(c, Button).Enabled = True
                End If
                If c.Name = "btnClear" Then
                    CType(c, Button).Enabled = True
                End If
                If c.Name = "btnExit" Then
                    CType(c, Button).Enabled = True
                End If
            End If
            If TypeOf c Is Label Then
                If c.Name = "lblProcessArea" Then
                    CType(c, Label).Enabled = True
                End If
                If c.Name = "lblCurrentDT" Then
                    CType(c, Label).Enabled = True
                End If
            End If
            If TypeOf c Is DataGridView Then
                If c.Name = "dgvPMData" Then
                    CType(c, DataGridView).Enabled = True
                End If
            End If
            If TypeOf c Is MenuStrip Then
                If c.Name = "MenuStrip1" Then
                    CType(c, MenuStrip).Enabled = True
                End If
            End If
        Next
    End Sub

** FORM LOAD -- **

Private Sub frmPartsM_Load(sender As Object, e As EventArgs) Handles MyBase.Load

            Call DisableAll()

            lblCurrentDT.Text = DateTime.Now.ToString("dd-MMM-yyyy hh:mm:ss")
            ToolTip1.SetToolTip(btnDelete, "Delete")
            ToolTip1.SetToolTip(btnEdit, "Edit")
            ToolTip1.SetToolTip(btnClear, "Clear")
            ToolTip1.SetToolTip(btnExit, "Close")
            'ToolTip1.SetToolTip(btnSearch, "Search")
            ToolTip1.SetToolTip(btnSave, "Save")

            Call DGV()
            '###################################### PROCESS #################################################
            con.ConnectionString = "Data Source=APBIPHAP06; Initial Catalog=PMT; Integrated Security=SSPI"

            Try
                con.Open()
                Dim strSQL As String = "Select * from tblProcess"
                Dim da As New SqlDataAdapter(strSQL, con)
                Dim ds As New DataSet
                da.Fill(ds, "tblProcess") 'table name

                With cmbProcess
                    .DataSource = ds.Tables("tblProcess") 'table name
                    .DisplayMember = "Process" 'column name
                    .ValueMember = "Process" 'column name
                    .SelectedIndex = -1
                End With

            Catch ex As Exception
                MessageBox.Show("Error while connecting to SQL Server." & ex.Message)
            Finally
                con.Close()
            End Try

            '--- AND SO ON..

which controls you want to disable. in your sub procedure DisableAll() you have tried to enable each and every controls except cmbLineNo ComboBox.
How do you get every controls are disabled.

Your Procedure is too much lengthy. you can shorten it.

Private Sub DisableAll()

        For Each c As Control In Me.Controls

            If TypeOf c Is ComboBox Then
                If c.Name = "cmbProcess" Then
                    c.Enabled = True
                Else
                    c.Enabled = False
                End If
            Else
                c.Enabled = True
            End If

        Next

End Sub

Hope it can help you.

I want to disable all text fields and combo boxes but buttons will remain enable.
Anyway, I already solved it, just right after I post this discussion. And thank you for trimming my code. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.