Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compile Exe
#Dim All
%Unicode=1
%IDC_ListView = 500
%IDC_Button = 501
#Include "win32api.inc"
Global hDlg As Dword 'main dialog handle
Function PBMain() As Long
Local i As Long
Dialog Default Font "Tahoma",12,1
Dialog New Pixels, 0, "ListView Test",300,300,250,500,%WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 200, "Remove",10,10,100,25
Control Add ListView, hDlg, %IDC_ListView, "", 10,40,220,450
ListView Insert Column hDlg, %IDC_ListView, 1, "ListView", 220, 0
For i = 1 To 20 : ListView Insert Item hDlg, %IDC_ListView, 1, 0, Str$(i) : Next i
ListView Select hDlg, %IDC_ListView, 10
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
If Cb.Msg = %WM_Command And Cb.Ctl = 200 Then DeleteSelectedRow
End Function
Sub DeleteSelectedRow
Local iCount,iRow As Long
ListView Get Select hDlg, %IDC_ListView To iRow
If iRow = 0 Then WinBeep(200,300) : Exit Sub '<--- if no selection, do nothing
ListView Get Count hDlg, %IDC_ListView To iCount
ListView Delete Item hDlg, %IDC_Listview, iRow
ListView Select hDlg, %IDC_ListView, Min(iRow,iCount-1) '<--- move bottom of the list up
ListView_SetItemState GetDlgItem(hDlg,%IDC_ListView), Min(iRow,iCount-1)-1, %LVIS_Focused, %LVIS_Focused '<--- keyboard synchronizing code
Control Set Focus hDlg, %IDC_ListView
End Sub
http://www.garybeene.com/sw/gbsnippets.htm