2020年5月9日 星期六

VB.NET 上下移動ListView的Item [Move ListView item Up Down ]


 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
    Private Sub btnSortUp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSortUp.Click

        If lvwSort.FocusedItem Is Nothing Then

            Exit Sub

        End If


        Dim tItem As ListViewItem

        Dim intItem As Integer = lvwSort.SelectedIndices.Item(0)


        If intItem = 0 Then

            MsgBox("El dato ya esta en Primer lugar", 16, "Error")

            Exit Sub

        End If


        tItem = lvwSort.Items(intItem - 1)

        lvwSort.Items(intItem - 1) = lvwSort.Items(intItem).Clone

        lvwSort.Items(intItem) = tItem.Clone

        lvwSort.Items(intItem - 1).Selected = True

        lvwSort.Select()

    End Sub


 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
    Private Sub btnSortDown_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSortDown.Click

        If lvwSort.FocusedItem Is Nothing Then

            Exit Sub

        End If


        Dim tItem As ListViewItem

        Dim intItem As Integer = lvwSort.SelectedIndices.Item(0)


        If intItem = lvwSort.Items.Count - 1 Then

            MsgBox("El dato ya esta en Ultimo lugar", 16, "Error")

            Exit Sub

        End If


        tItem = lvwSort.Items(intItem + 1)

        lvwSort.Items(intItem + 1) = lvwSort.Items(intItem).Clone

        lvwSort.Items(intItem) = tItem.Clone

        lvwSort.Items(intItem + 1).Selected = True

        lvwSort.Select()


    End Sub

沒有留言:

張貼留言