i want to get the row(s) when the checkbox is check/uncheck in the listview.. thank u...

For Each Item In CheckedItems
   If (Item.SubItems(4).Text) = "Cash" Then
	'Code Here
   ElseIf (Item.SubItems(4).Text) = "Check" Then	
	'Code Here
   End If
Next
        
  If (e.CurrentValue = CheckState.Checked) Then
    If LstvwBankDeposits.Items(0).SubItems(4).Text = "Cash" Then
	'Code Here
    ElseIf LstvwBankDeposits.Items(0).SubItems(4).Text = "Check" Then
      'Code Here
    End If

  ElseIf (e.CurrentValue = CheckState.Unchecked) Then
   If LstvwBankDeposits.Items(0).SubItems(4).Text = "Cash" Then
	'Code Here
   ElseIf LstvwBankDeposits.Items(0).SubItems(4).Text = "Check" Then
	'Code Here
   End if 
  End if

See if this helps.

For Each itm As ListViewItem In ListView1.Items
            If itm.Checked Then
                MsgBox("item checked: " & itm.Text)
            Else
                MsgBox("item NOT checked: " & itm.Text)
            End If
        Next
commented: Great... yoU are Great... +1

thank u for that...
still it is not working properly...
if i check the checkbox a msgbox will pop up.. "item NOT checked"...

For Each cb As Control In Me.Controls
    If cb.GetType.ToString = "System.Windows.Forms.CheckBox" Then
        boxNo = cb.Name()
        boxNo = boxNo.Substring(4)
	Dim tempCB As CheckBox = DirectCast(cb, CheckBox)
                                
        If tempCB.Checked = True Then
           MsgBox("Checked" & boxNo)
        Else
           MsgBox("Unchecked" & boxNo)
        End If
                               
     End If
Next

The SubString() line will remove the first 4 characters and keep the remaining. Normally, the name of the box has a number at the end. Simply take the number of characters before the number and place it here.

thank u for that...
still it is not working properly...
if i check the checkbox a msgbox will pop up.. "item NOT checked"...

Try my code in a New Project and let me know if you get the same results.

Try my code in a New Project and let me know if you get the same results.

what do you mean? where i can find that... thanx..

Start a new project. Only add a ListView (with checkboxes) and a Button.
Load some items in the ListView and test the code I have posted. It should respond as needed.

Try my code in a New Project and let me know if you get the same results.

sorry for that... what i mean is, if the user checks the lstvw in runtime it cannot detect if that row is check if i put it in itemcheck... hope it is clear... tnx

Please post your entire code in the Sub that checks for checked/not checked items.

Please post your entire code in the Sub that checks for checked/not checked items.

Private Sub LstvwBankDeposits_ItemCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles LstvwBankDeposits.ItemCheck
        Try
            Dim Cash As Double = 0.0
            Dim Cheque As Double = 0.0
            Dim Other As Double = 0.0

            Dim CheckedItems As ListView.CheckedListViewItemCollection = LstvwBankDeposits.CheckedItems
            Dim Item As New ListViewItem

            For Each Item In CheckedItems
                If (Item.SubItems(4).Text) = "Check" Then
                    Cheque += Double.Parse(Item.SubItems(3).Text)
                    LblTotalCheques.Text = CType(Cheque, String)
                    LblTotalCheques.Text = FormatNumber(LblTotalCheques.Text, 2)

                ElseIf (Item.SubItems(4).Text) = "Cash" Then
                    Cash += Double.Parse(Item.SubItems(3).Text)
                    LblTotalCash.Text = CType(Cash, String)
                    LblTotalCash.Text = FormatNumber(LblTotalCash.Text, 2)
                End If
            Next

            If LstvwBankDeposits.Items(1).SubItems(4).Text = "Cash" Then
                If e.CurrentValue = CheckState.Unchecked Then
                    Cash += Double.Parse(Me.LstvwBankDeposits.Items(e.Index).SubItems(3).Text)
                    LblTotalCash.Text = CType(Cash, String)
                    LblTotalCash.Text = FormatNumber(LblTotalCash.Text, 2)
                ElseIf e.CurrentValue = CheckState.Checked Then
                    Cash -= Double.Parse(Me.LstvwBankDeposits.Items(e.Index).SubItems(3).Text)
                    LblTotalCash.Text = CType(Cash, String)
                    LblTotalCash.Text = FormatNumber(LblTotalCash.Text, 2)
                End If

            ElseIf LstvwBankDeposits.Items(1).SubItems(4).Text = "Check" Then
                If e.CurrentValue = CheckState.Unchecked Then
                    Cheque += Double.Parse(Me.LstvwBankDeposits.Items(e.Index).SubItems(3).Text)
                    LblTotalCheques.Text = CType(Cheque, String)
                    LblTotalCheques.Text = FormatNumber(LblTotalCheques.Text, 2)
                ElseIf e.CurrentValue = CheckState.Checked Then
                    Cheque -= Double.Parse(Me.LstvwBankDeposits.Items(e.Index).SubItems(3).Text)
                    LblTotalCheques.Text = CType(Cheque, String)
                    LblTotalCheques.Text = FormatNumber(LblTotalCheques.Text, 2)
                End If

            End If
          

        Catch ex As Exception
            MsgBox(Err.Description, MsgBoxStyle.OkOnly, "Error")
        End Try
    End Sub

See if this helps.

Private Cash As Double = 0.0, Cheque As Double = 0.0, Other As Double = 0.0 '// declare once.

    Private Sub LstvwBankDeposits_ItemChecked(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemCheckedEventArgs) Handles LstvwBankDeposits.ItemChecked
        LblTotalCheques.Text = "0.0" : LblTotalCash.Text = "0.0" '// reset to 0.
        Cash = 0.0 : Cheque = 0.0 : Other = 0.0 '// reset to 0.
        For Each lvItem As ListViewItem In LstvwBankDeposits.CheckedItems '// Loop through only the Checked items.
            Select Case lvItem.SubItems(4).Text
                Case "Cash"
                    Cash += Double.Parse(lvItem.SubItems(3).Text)
                    With LblTotalCash
                        .Text = CType(Cash, String)
                        .Text = FormatNumber(.Text, 2)
                    End With
                Case "Check"
                    Cheque += Double.Parse(lvItem.SubItems(3).Text)
                    With LblTotalCheques
                        .Text = CType(Cheque, String)
                        .Text = FormatNumber(.Text, 2)
                    End With
            End Select
        Next
    End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.