Results 1 to 5 of 5

Thread: ListView : Finding out what line has been checked

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2003
    Posts
    21

    ListView : Finding out what line has been checked

    Hi,

    Is there anyway to find out what line the user has just checked in a ListView control with check boxes?

    I can tell they've checked something, and I can get an enumerator of all the checked items, but I need to know which specific item was checked at the time that it's checked.

    Thanks in advance,
    Liam.

  2. #2
    Addicted Member AlvaroF1's Avatar
    Join Date
    Sep 2002
    Location
    SP - Brazil
    Posts
    200
    VB Code:
    1. Dim myItem As ListViewItem
    2.     Dim myChecked As ListView.CheckedListViewItemCollection
    3.     myChecked = ListView1.CheckedItems
    4.     For Each myItem In myChecked
    5.         'do something
    6.     Next

  3. #3
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    or easier still ....
    VB Code:
    1. [COLOR=blue]Dim[/color] lvItem [COLOR=blue]As[/color] ListViewItem
    2.         [COLOR=blue]For Each[/color] lvItem [COLOR=blue]In[/color] ListView1.CheckedItems
    3.             MessageBox.Show(lvItem.Text)
    4.         [COLOR=blue]Next[/color]
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  4. #4
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    oops i think we missread what you want, you only want to check the item that gets checked ( so to speak )
    VB Code:
    1. [COLOR=BLUE]Private[/COLOR] [COLOR=BLUE]Sub[/COLOR] ListView1_ItemCheck([COLOR=BLUE]ByVal[/COLOR] sender [COLOR=BLUE]As[/COLOR] [COLOR=BLUE]Object[/COLOR], [COLOR=BLUE]ByVal[/COLOR] e [COLOR=BLUE]As[/COLOR] System.Windows.Forms.ItemCheckEventArgs) [COLOR=BLUE]Handles[/COLOR] ListView1.ItemCheck
    2.         [COLOR=BLUE]Dim[/COLOR] lvItem [COLOR=BLUE]As[/COLOR] ListViewItem = [COLOR=BLUE]DirectCast[/COLOR](sender, ListViewItem)
    3.         MessageBox.Show(lvItem.Text & "  you just checked this item!")
    4.     [COLOR=BLUE]End[/COLOR] [COLOR=BLUE]Sub[/COLOR]
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Mar 2003
    Posts
    21
    Nice and simple code! I'll give it a go.

    Thanks for the help!

    Best regards,
    Liam.

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