Results 1 to 6 of 6

Thread: How to check the checkboxes in the listview?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2010
    Posts
    309

    How to check the checkboxes in the listview?

    Hi guys,

    I am working on my listview which I have almost finish it, but i need to work on the button event to check for each string in the listview whether if the checkbox is true or false. When I tick and untick on the checkboxes to add the strings in the label, I want to know how i can check them out through on the listview to see if the checkbox is true or false?


    Here's the code:

    Code:
    Private Function GetEnabledDisabledText(ByVal enabled As Boolean) As String
    	Return (If(enabled, "Enabled", "Disabled"))
    End Function
    
    Private Shared subItems1 As New List(Of String)()
    
    Private Sub listView1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
    	Dim strItem As String = listView1.HitTest(e.Location).Item.SubItems(1).Text
    
    	If subItems1.Contains(strItem) Then
    	   subItems1.Remove(strItem)
    	Else
    	   subItems1.Add(listView1.HitTest(e.Location).Item.SubItems(1).Text)
    	End If
    	
    	label3.Text = String.Join(", ", subItems1.ToArray())
    End Sub
    
    Private Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    	button1.Enabled = False
    	Dim a() As String = Nothing
    	a = label3.Text.Split(","c)
    	Dim j As Integer = 0
    	Dim str As Object = GetEnabledDisabledText(listView1.Items(j).Checked)
    	MessageBox.Show(a(j).Trim() & " is " & str.ToString())
    End Sub
    Do you know how I can get the messagebox to display and tells me if the checkboxes in the listview compare to each string that I add in the label is true or false?

    Can anyone help me with this?

  2. #2
    Addicted Member
    Join Date
    Sep 2011
    Location
    Seattle
    Posts
    218

    Re: How to check the checkboxes in the listview?

    I have absolutely no idea what you are asking.

    Can you break down the steps of your program using:

    1.
    2.
    3.
    4.

    And then tell us what part of that sequence you are having trouble with.

    Right now, the best I can gather is:

    1. The program loads up
    2. You add items to a listbox
    3. You can check or uncheck items in the listbox
    4. You click a button
    5. If the item is unchecked it is deleted?
    6. A message box appears with what items are checked.

    I have no idea where the label fits in, so be more descriptive when you write out the steps

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2010
    Posts
    309

    Re: How to check the checkboxes in the listview?

    Ok, here is a break down of a step of what I want to do:

    1. The program loads up
    2. I add the items to a listview
    3. I tick and untick the items in the listview to add each strings in the label like mystrings 1, mystrings 2
    4. I click a button to split the strings in the label and check each strings from the label to the listview to see if each strings in the listview have checked and unchecked checkboxes
    5. A message box appears with each items if the checkboxes are checked or unchecked.


    Hope it will make sense of what i am trying to do.

  4. #4
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: How to check the checkboxes in the listview?

    If you are adding Strings from clicking checks in the ListView, then its not necessary to go over the list in the Label to match them to a ListView item since it was the ListView that created them in the first place. That's really not efficient. Why would you want to do that anyway ?
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  5. #5
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: How to check the checkboxes in the listview?

    Quote Originally Posted by PillKilla View Post
    3. I tick and untick the items in the listview to add each strings in the label like mystrings 1, mystrings 2

    #3 - So the listview string item is added to a label when you tick a checkbox and also when you untick a checkbox?

    BTW you asked this same question a couple days ago here, whats changed? Why not reply to that thread?

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2010
    Posts
    309

    Re: How to check the checkboxes in the listview?

    Quote Originally Posted by Edgemeal View Post

    #3 - So the listview string item is added to a label when you tick a checkbox and also when you untick a checkbox?

    BTW you asked this same question a couple days ago here, whats changed? Why not reply to that thread?

    Yes, when i tick and untick a checkbox, it will add the string item to a label.

    So now I am working on the button event to compare the string item from a label and the listview as i want to check if the listview items is true or false. Can you please help me with that?

    As for my previous thread, nobody is answers so i think i would start a new one and explains a bit better.

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