2020年5月15日 星期五

vb.net CheckBox控制ListView的ItemChecked [CheckBox Control ListView]


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
    Private Sub lvwLista_ItemChecked(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemCheckedEventArgs) Handles lvwLista.ItemChecked

        Dim blnAll As Boolean = True

        Dim blnAllCHK As Boolean = e.Item.Checked

        For Each lvwi As ListViewItem In lvwLista.Items

            If lvwi.Checked = Not e.Item.Checked Then

                blnAll = False

                Exit For

            End If

        Next


        If blnAll = True Then

            If e.Item.Checked = True Then


                chkSelect.CheckState = CheckState.Checked

            Else

                chkSelect.CheckState = CheckState.Unchecked

            End If

        Else

            chkSelect.CheckState = CheckState.Indeterminate

        End If


    End Sub




 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
    Private Sub chkSelect_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkSelect.Click

        If chkSelect.Checked = True Then

            For Each lvwi As ListViewItem In lvwLista.Items

                lvwi.Checked = True

            Next

        Else

            For Each lvwi As ListViewItem In lvwLista.Items

                lvwi.Checked = False

            Next

        End If

    End Sub

沒有留言:

張貼留言