Alright I am going to try to put this in the least confusing way possible. I have a form that contains multiple textboxes. These textboxes are initially disabled and their text has been grabbed from a file that has been read in. No problems yet. There are 20 lines that are read in and these "should" never be changed but I want to let the user have the opportunity (with a strict warning of course). So I have setup checkboxes next to each line that if clicked, the textboxes for that line become enabled and the user can change the text. If the user clicks the checkbox I have a YesNoCancel dialog popup and if the user clicks 'No' I want the textboxes for that line to remain disabled [/I]and[/I] the checkbox to revert back to being unchecked.

Here's my problem. Let's say the user does click yes when clicking the checkbox. He/She then makes changes to the textboxes. Then, "oops!" those changes were wrong. So then the user would click on the checkbox again only this time (since it was already checked) a different YesNoCancel dialog comes up but this time saying "Revert to Defaults?". Everything I've tried ends up displaying two dialog boxes.

Private Sub chkLine1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkLine1.CheckedChanged

        If chkLine1.CheckState = CheckState.Checked Then
            If MessageBox.Show("Are you sure you want to change the Header field values?", "Change Header Fields", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation) = Windows.Forms.DialogResult.Yes Then
                txtLn01_DefaultText.Enabled = True
                txtLn01_StartDate.Enabled = True
                txtLn01_StartTime.Enabled = True
            Else
                chkLine1.Checked = False
                txtLn01_DefaultText.Enabled = False
                txtLn01_StartDate.Enabled = False
                txtLn01_StartTime.Enabled = False
            End If
        [B]Else[/B]
            If MessageBox.Show("Are you sure? Doing so will cause all values to be reset to their defaults.", "Reset to Defaults?", MessageBoxButtons.YesNoCancel) = Windows.Forms.DialogResult.Yes Then
                txtLn01_DefaultText.Enabled = False
                txtLn01_StartDate.Enabled = False
                txtLn01_StartTime.Enabled = False
                txtLn01_DefaultText.Text = AD.DF.Header.Ln01_DefaultText
                txtLn01_StartDate.Text = AD.DF.Header.Ln01_StartDate
                txtLn01_StartTime.Text = AD.DF.Header.Ln01_StartTime
            End If
        End If


    End Sub

Basically what I need to know is: how can I make a checkbox, after its been clicked, not change its state until the user clicks yes or no?

Just a thought: You could immediately change it back to what it was, then ask and do the change yourself.

checkBox = unchecked
if( user-click-checks ){
checkBox = unchecked
userMsg(Are you sure?)
if(yes)
checkBox = checked
}

About displaying 2 message boxes, I somehow managed to put something together with setting a Boolean to True/False.

Private allowCheck As Boolean = True

    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
       Select Case CheckBox1.Checked
            Case True
                allowCheck = False
                If MessageBox.Show("Are you sure you want to change the Header field values?" _
                                   , "Change Header Fields", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation) _
                               = Windows.Forms.DialogResult.Yes Then
                    TextBox1.Enabled = True
                    TextBox2.Enabled = True
                    TextBox3.Enabled = True
                    allowCheck = True
                Else
                    CheckBox1.Checked = False
                    TextBox1.Enabled = False
                    TextBox2.Enabled = False
                    TextBox3.Enabled = False
                End If
            Case False
                If allowCheck = True Then
                    If MessageBox.Show("Are you sure? Doing so will cause all values to be reset to their defaults.", "Reset to Defaults?", MessageBoxButtons.YesNoCancel) = Windows.Forms.DialogResult.Yes Then
                        TextBox1.Enabled = False
                        TextBox2.Enabled = False
                        TextBox3.Enabled = False
                        TextBox1.Text = "AD.DF.Header.Ln01_DefaultText"
                        TextBox2.Text = "AD.DF.Header.Ln01_StartDate"
                        TextBox3.Text = "AD.DF.Header.Ln01_StartTime"
                    End If
                End If
        End Select
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        CheckBox1.Checked = True
    End Sub

If it wasn't so late, the above code might actually make some sense to me :yawn: a little better, but overall, you should only get one msgbox per checkstate.

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.