mardi 11 août 2015

Managing `CheckBox_Checked` Event without an infinite loop

I know this seems like an easy fix, but I am having trouble. I have a CheckBox, when checked, I remove the data source of a DataGridView on my Windows Form and remove the ReadOnly properties of a few Textbox.

I know the CheckedChanged event will send my code into an infinite loop, but I cannot figure out which event would handle this change without changing the CheckedState each time. I have tried using Click, MouseClick, and CheckStateChanged events with no luck.

This is my current code:

Private Sub chkManual_MouseClick(sender As Object, e As EventArgs) Handles chkManual.MouseClick

        If Not Me.chkManual.Checked Then
        Me.chkManual.Checked = False
        Me.cbRegion.SelectedIndex = -1

        Me.txtIssueDate.ReadOnly = True
        Me.txtCasenum.ReadOnly = True
        Me.txtCommnum.ReadOnly = True

        Exit Sub

   Else
        Me.dgDataEntry.DataSource = Nothing
        Me.cbRegion.SelectedIndex = -1

        Me.txtIssueDate.ReadOnly = False
        Me.txtCasenum.ReadOnly = False
        Me.txtCommnum.ReadOnly = False
        ClearForm()

        frmPDF.Hide()
        Exit Sub
    End If
    End Sub

Properties of CheckBox: AutoCheck = True, Checked = False, and CheckState = Unchecked

I have looked into these already:

CheckBox_Checked event

Is there a simpler way to process check boxes?

CheckBox reverts to checked after being unchecked

How to check if a checkboxes state has changed

How can I prevent an assignment statement to CheckBox.Checked from raising the CheckChanged event?

http://ift.tt/1IWKeZP




Aucun commentaire:

Enregistrer un commentaire