Results 1 to 2 of 2

Thread: [RESOLVED] MsgBoxResult.Yes

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2011
    Posts
    44

    Resolved [RESOLVED] MsgBoxResult.Yes

    Hello everyone,
    I am making an application that has employees in a listview.
    When the client clicks on one of the employees end clicks the remove button I wan to ask the client if they want to remove the employee.
    The problem is when I click NO it still removes the Item from the listview.

    My code:

    lvEmployees is my listview name.

    VB.net
    Code:
     For I = 0 To lvEmployees.SelectedItems.Count - 1
                    If Not I = -1 Then
                        MsgBox("Do you really want to remove " & lvEmployees.Items.Item(I).Text & " " & lvEmployees.Items.Item(I).SubItems(1).Text & "?", MsgBoxStyle.YesNo)
    
                        If MsgBoxResult.Yes Then
                            lvEmployees.SelectedItems.Item(I).Remove()
                        Else
                            Exit Sub
                        End If
    
                    End If
                Next
    Thanks for the help.
    Last edited by pietercdevries; Aug 16th, 2012 at 12:10 PM.

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: MsgBoxResult.Yes

    For starters, I'd suggesting using MessageBox.Show instead...
    Secondly, if you then read the documentation you'll find out that it is a function... which means it returns the value ... so it works like this:
    Code:
        Dim result = MessageBox.Show(message, caption, _
                                     MessageBoxButtons.YesNo, _
                                     MessageBoxIcon.Question)
    
        ' If the no button was pressed ... 
        If (result = DialogResult.No) Then 
            ' cancel the closure of the form.
            e.Cancel = True 
        End If
    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width