msgbox.okcancel result error.

Ive got this procedure to delete a row from a datatable. I'm asking the user to confirm the action using the msgbox but what ever the user clicks the msgboxresult.ok code is being run, even if cancel is being clicked......
Any1 help?

Private Sub DeleteTitle()
        Try
            Dim DeleteCmdBuilder As New OleDbCommandBuilder(myDataAdapter)
            Dim myDeleteRow As DataRow '= New myDataTable.Rows
            Dim i As Integer
            'myDataAdapter.Fill(myDataTable)

            MsgBox("You Are About To Delete Job Title '" & cmbSrcTitle.Text & "'..Do You Want To Continue?", _
        MsgBoxStyle.OKCancel, "Job Title Deletion")

            If MsgBoxResult.OK Then   ' User chose Yes.
                For Each myDeleteRow In myDataTable.Rows
                    If myDeleteRow("strJobTypeTAG") = cmbSrcTitle.Text Then
                        myDeleteRow.Delete()
                        myDataAdapter.Update(myDataTable)
                        myDataTable.AcceptChanges()
                        NewPageFormat()
                        Exit For
                    End If
                Next
            ElseIf MsgBoxResult.Cancel Then
                myDataTable.RejectChanges()
            End If

        Catch e As Exception
            MsgBox(e.ToString)
            End
        End Try
    End Sub
scm0smlAsked:
Who is Participating?
 
TimCotteeHead of Software ServicesCommented:
Hi scm0sml,

            Dim Result As Integer = MsgBox("You Are About To Delete Job Title '" & cmbSrcTitle.Text & "'..Do You Want To Continue?", _
        MsgBoxStyle.OKCancel, "Job Title Deletion")

            If Result = MsgBoxResult.OK Then   ' User chose Yes.

MsgboxResult.OK is a value and not the result of the msgbox, you need to assign the returned value from the msgbox call to a variable and then test the variable.

Tim Cottee
0
 
scm0smlAuthor Commented:
ok = 1, cancel =2 is it?
0
 
scm0smlAuthor Commented:
got it, cheers!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.