Results 1 to 6 of 6

Thread: listview control with a checkbox in VS 2015

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2016
    Posts
    34

    listview control with a checkbox in VS 2015

    I have a listview control on a form. The first column has been set to be a checkbox for the purpose of a user checking the item to be "flagged". I want to update a database when a user checks a record in the listview by checking the checkbox. I am trying to get the row number or index of the checkbox where that checkbox is that was checked but can't. In other words, I want to get the index of the row that that checkbox is on when it has been checked. Once I have that then I get a subitem text from that row to pass the database command. I can get the index when I select in the area right next to the checkbox in that same column on that row but cab't get it when just the checkbox has been checked. I don't want to loop thru all the items in the listview and check each one.

    Any help will be appreciated. TIA

    Bill

  2. #2
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: listview control with a checkbox in VS 2015

    There are two events you can use ItemChecked and ItemCheck



  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2016
    Posts
    34

    Re: listview control with a checkbox in VS 2015

    Thanks. Can you be a little more specific and provide some sample code, I'd very much appreciate it?

  4. #4
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: listview control with a checkbox in VS 2015

    Clicking the links should help... there's usually sample code on MSDN.

    -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??? *

  5. #5

    Thread Starter
    Member
    Join Date
    Jan 2016
    Posts
    34

    Re: listview control with a checkbox in VS 2015

    tg
    Thank you. I did check the links but still am having a hard time with this. Tried applying some of the code in the links without success. MS's documentation is sometimes very confusing to me. If you don't want to post some sample code then I understand. Tried all of these without success and tried using the properties you referenced also with no success

    With lvwFromRepData
    Dim itemNoChecked As Integer = 0
    Dim ItemSelected As String = ""
    itemNoChecked = .Items(.SelectedIndices(0)).Index
    itemNoChecked = .FocusedItem.Index
    itemNoChecked = .SelectedIndices(0)
    itemNoChecked = .SelectedItems(0).Index
    'get vluae of a specific column in the listview once the row has been determined
    ItemSelected = .Items(itemNoChecked).SubItems(2).Text
    ItemSelected = .SelectedItems(1).SubItems(2).Text


    End With

  6. #6
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: listview control with a checkbox in VS 2015

    e argument contains the item that fired the event, you can use it to gather data you want, e.g.

    Code:
        Private Sub ListView1_ItemChecked(sender As Object, e As ItemCheckedEventArgs) Handles ListView1.ItemChecked
            If e.Item.Checked Then
                MessageBox.Show(Me, "Item Checked Index is " & e.Item.Index & Environment.NewLine & "Item Checked SubItems(2) is " & e.Item.SubItems(2).Text, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Information)
            Else
                MessageBox.Show(Me, "Item Un-Checked Index is " & e.Item.Index & Environment.NewLine & "Item Un-Checked SubItems(2) is " & e.Item.SubItems(2).Text, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Information)
            End If
        End Sub



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