Private Sub list1_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer) if keycode=vbKeyDelete then list1.remove list1.listindex '按DEL会删除当前选中的那一行 end if End Sub
接受按键事件判断是否del键被按下如果是,删除当前选中的那一行
Private Sub Form_Load() List1.AddItem "a" List1.AddItem "b" List1.AddItem "c" List1.AddItem "d" List1.AddItem "e" List1.AddItem "f" List1.AddItem "g" List1.AddItem "h" End Sub Private Sub List1_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = 46 Then If List1.ListIndex <> -1 Then List1.RemoveItem List1.ListIndex End If End If End Sub
if keycode=vbKeyDelete then
list1.remove list1.listindex '按DEL会删除当前选中的那一行
end if
End Sub
List1.AddItem "a"
List1.AddItem "b"
List1.AddItem "c"
List1.AddItem "d"
List1.AddItem "e"
List1.AddItem "f"
List1.AddItem "g"
List1.AddItem "h"
End Sub
Private Sub List1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 46 Then
If List1.ListIndex <> -1 Then
List1.RemoveItem List1.ListIndex
End If
End If
End Sub
我就是这么用的。