21 | 09 | 2017

Keydown Control Event

The Keydown event of a control can be used to anticipate on users keyboard strokes. The code below can be added to a Userform with Listview. The code adds sample data. When hitting the Delete button (Keycode 46) then the selected row of the listview will be removed.

Private Sub UserForm_Initialize()
'*************************************
'**DownloadedfromVisibleVisual.com**
'*************************************
'FillalistviewcalledListview1withsampledata
With Listview1
.AddItem"Row1"
.AddItem"Row2"
.AddItem"Row3"
.AddItem"Row4"
.AddItem"Row5"
.AddItem"Row6"
.AddItem"Row7"
End With
End Sub
Private Sub Listview1_KeyDown(KeyCode As Integer,Shift As Integer)
'Keycode46representstheDelbutton
If KeyCode=46 Then Listview1.RemoveItem(Listview1.ListIndex)
'Shiftreturna0or1wheneathertheShiftbuttonispressedornot
End Sub
 
All VB keycodes are stated below:
Button KeyCode
Left Button 1
Right Button 2
Cancel 3
Mbutton 4
Back 8
Tab 9
Clear 12
Return 13
Shift 16
Control 17
Menu 18
Pause 19
Capital 20
Escape 27
Space 32
PageUp 33
PageDown 34
End 35
Home 36
Left 37
Up 38
Right 39
Down 40
Select 41
Print 42
Execute 43
Snapshot 44
Insert 45
Delete 46
Help 47
Numlock 144
ScrollLock 145
A 65
B 66
C 67
D 68
E 69
F 70
G 71
H 72
I 73
J 74
K 75
L 76
M 77
N 78
O 79
P 80
Q 81
R 82
S 83
T 84
U 85
V 86
W 87
X 88
Y 89
Z 90
0 48
1 49
2 50
3 51
4 52
5 53
6 54
7 55
8 56
9 57
Numpad0 96
Numpad1 97
Numpad2 98
Numpad3 99
Numpad4 100
Numpad5 101
Numpad6 102
Numpad7 103
Numpad8 104
Numpad9 105
Multiply 106
Add 107
Separator 108
Subtract 109
Decimal 110
Divide 111
F1 112
F2 113
F3 114
F4 115
F5 116
F6 117
F7 118
F8 119
F9 120
F10 121
F11 122
F12 123
F13 124
F14 125
F15 126
F16 127
Login

Sign up now and upload your code to the website.

Help us to continue.....
Statistics
Articles View Hits
2355349
Latest Articles