2020年5月17日 星期日

vb.net Listview可直接修改Subitem (模擬Excel) [Listview item modify like Excel]


 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
   Dim hitinfo As ListViewHitTestInfo

    Dim txtTempC As New TextBox


    Private Sub frmRegistrar_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        lvFormat(lvwCaballero)


        txtTempC.Parent = lvwCaballero

        txtTempC.Hide()

        AddHandler txtTempC.LostFocus, AddressOf txtTempC_LostFocus


    End Sub


    Private Sub txtTempC_LostFocus(sender As Object, e As EventArgs)


        hitinfo.SubItem.Text = txtTempC.Text

        txtTempC.Hide()

    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
36
37
38
39
40
    Private Sub lvwCaballero_MouseDoubleClick(sender As Object, e As MouseEventArgs) Handles lvwCaballero.MouseDoubleClick

        hitinfo = lvwCaballero.HitTest(e.X, e.Y)

        'If hitinfo.Item.SubItems.IndexOf(hitinfo.SubItem) Then

        txtTempC.Bounds = hitinfo.SubItem.Bounds

        'txtTempC.Bounds = hitinfo.Item.SubItems(1).Bounds

        txtTempC.Text = hitinfo.SubItem.Text

        txtTempC.Focus()

        txtTempC.Show()

    'End If

    End Sub


    Private Sub lvFormat(lvw As ListView)

        With lvw

            .View = View.Details

            .GridLines = True

            .FullRowSelect = True

            .Sorting = SortOrder.Ascending

            .Columns.Add("姓名", 200)

            .Columns.Add("", 56)

        End With

    End Sub

沒有留言:

張貼留言