I have a listbox in my program and a command button. When the user selects an item form the listbox and clicks the command button, a message box is shown which asks the user to confirm selection and has yes and no options to enable this.

If the user clicks yes it will accept the selection, i can do this.

I want the program to be able to offer the message box for confirmation two times after it has first been shown and after the no button is selected each time i want it to go back to the listbox to allow selection. On the third time i want it to automatically accept the choice and not offer confirmation as before.

Dim b As Integer
        Dim inputno As Integer
        inputno = 3
        Dim dlgRes As DialogResult

            dlgRes = MessageBox.Show(" Do you wish to select this item", "Confirm choice", MessageBoxButtons.YesNo)

            If dlgRes = DialogResult.Yes Then
 listboxselect.SelectedIndex = selecteditem
            End If
8 Years
Discussion Span
Last Post by bcasp

k so you want: User -> selection -> confirmation message ->user says no -> back to selecttion -> confirmation message -> user says no -> back to selection -> no confirmation and just accepts?

if so this is the rough outline of how you do it:
while tries <= 2
msgbox("are you sure?")
tries = tries + 1
end while


You would probably have to play with the count and where the message box is displayed to get this to be exactly what you want, but I think something like this should work.

Public Class Form1

    Dim numTries As Short

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        numTries = 0
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If ListBox1.SelectedIndex <> -1 Then
            Dim diagResult As DialogResult = MessageBox.Show("Do you wish to select this item", "Confirm choice", MessageBoxButtons.YesNo)
            If diagResult <> DialogResult.Yes And numTries < 3 Then
                numTries = numTries + 1
            ElseIf diagResult = DialogResult.Yes Or numTries >= 3 Then
                MessageBox.Show("Do whatever")
            End If
        End If
    End Sub
End Class
Votes + Comments
very good thanks you solved it
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.