|
Расположите на форме элемент ListBox и 2 элемента CommandButton. Установите свойство MultiSelect элемента ListBox в 1 или 2
Пример 1 основан на функции SendMessageBynum, Пример 2 - на функции SendMessage 'Пример 1
Private Declare Function
SendMessageBynum Lib "user32" Alias "SendMessageA" (ByVal hWnd As
Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const LB_SELITEMRANGE = &H19B
Private Sub Form_Load()
List1.AddItem "11"
List1.AddItem "22"
List1.AddItem "33"
End Sub
Private Sub Command1_Click()
Call SendMessageBynum(List1.hWnd, LB_SELITEMRANGE, 1, (List1.ListCount - 1))
End Sub
Private Sub Command2_Click()
Call SendMessageBynum(List1.hWnd, LB_SELITEMRANGE, 0, (List1.ListCount - 1))
End Sub
'Пример 2
Private Declare Function
SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long,
ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Const LB_SETSEL = &H185
Private Sub Form_Load()
List1.AddItem "111"
List1.AddItem "222"
List1.AddItem "333"
End Sub
Private Sub Command1_Click()
SendMessage List1.hwnd, LB_SETSEL, True, ByVal True
End Sub
Private Sub Command2_Click()
If List1.SelCount Then
SendMessage List1.hwnd, LB_SETSEL, False, ByVal True
Else
Command1_Click
End If
End Sub
|
|