Terenz Posted February 12, 2018 Share Posted February 12, 2018 (edited) expandcollapse popup#include <GuiConstants.au3> #include <GuiListView.au3> Global $ListView Global Const $WM_NOTIFY = 0x004E Global Const $VK_DELETE = 0x2E Opt("WinTitleMatchMode", 2) $main_GUI = GUICreate("GuiRegisterMsg Test", 225, 400, 300, 10) $ListView = GUICtrlCreateListView("Entry Name|Category", 5, 75, 195, 280, BitOR($LVS_SORTASCENDING, $LVS_SINGLESEL)) GUICtrlSendMsg($ListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES) GUICtrlSendMsg($ListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT) GUICtrlCreateListViewItem("Name 1|Category 1", $ListView) GUICtrlCreateListViewItem("Name 2|Category 2", $ListView) GUICtrlCreateListViewItem("Name 3|Category 2", $ListView) GUICtrlCreateListViewItem("Name 4|Category 2", $ListView) GUICtrlCreateListViewItem("Name 5|Category 2", $ListView) GUISetState() ;Register WM_NOTIFY events GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events") While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd ; WM_NOTIFY event handler Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam) #forceref $hWndGUI, $MsgID, $wParam Local $tagNMHDR, $event, $hwndFrom, $code, $taGLVKEYDOWN $tagNMHDR = DllStructCreate("int;int;int", $lParam) If @error Then Return $event = DllStructGetData($tagNMHDR, 3) Select Case $wParam = $ListView Select Case $event = $LVN_KEYDOWN $taGLVKEYDOWN = DllStructCreate("int;int;int;int;uint", $lParam) $code = Hex(DllStructGetData($taGLVKEYDOWN, 4), 2) Select Case $code = Hex($VK_DELETE, 2) _GUICtrlListView_DeleteItem ($ListView, Int(_GUICtrlListView_GetSelectedIndices ($ListView))) EndSelect EndSelect EndSelect $tagNMHDR = 0 $event = 0 $lParam = 0 EndFunc ;==>WM_Notify_Events The expected result, example if i'll delete the third item with DEL: It select the same index after removing the item I have try many way, like _GUICtrlListView_SetItemFocused but maybe i'm implement wrong. Some advice? Edited February 12, 2018 by Terenz Nothing is so strong as gentleness. Nothing is so gentle as real strength Link to comment Share on other sites More sharing options...
Anas Posted February 12, 2018 Share Posted February 12, 2018 Try this: expandcollapse popup#include <GuiConstants.au3> #include <GuiListView.au3> Global $ListView ;Global Const $WM_NOTIFY = 0x004E Global Const $VK_DELETE = 0x2E Opt("WinTitleMatchMode", 2) $main_GUI = GUICreate("GuiRegisterMsg Test", 225, 400, 300, 10) $ListView = GUICtrlCreateListView("Entry Name|Category", 5, 75, 195, 280, BitOR($LVS_SORTASCENDING, $LVS_SINGLESEL)) GUICtrlSendMsg($ListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES) GUICtrlSendMsg($ListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT) GUICtrlCreateListViewItem("Name 1|Category 1", $ListView) GUICtrlCreateListViewItem("Name 2|Category 2", $ListView) GUICtrlCreateListViewItem("Name 3|Category 2", $ListView) GUICtrlCreateListViewItem("Name 4|Category 2", $ListView) GUICtrlCreateListViewItem("Name 5|Category 2", $ListView) GUISetState() ;Register WM_NOTIFY events GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events") While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd ; WM_NOTIFY event handler Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam) #forceref $hWndGUI, $MsgID, $wParam Local $tagNMHDR, $event, $hwndFrom, $code, $taGLVKEYDOWN $tagNMHDR = DllStructCreate("int;int;int", $lParam) If @error Then Return $event = DllStructGetData($tagNMHDR, 3) Select Case $wParam = $ListView Select Case $event = $LVN_KEYDOWN $taGLVKEYDOWN = DllStructCreate("int;int;int;int;uint", $lParam) $code = Hex(DllStructGetData($taGLVKEYDOWN, 4), 2) Select Case $code = Hex($VK_DELETE, 2) $sel = Int(_GUICtrlListView_GetSelectedIndices ($ListView)) _GUICtrlListView_DeleteItem ($ListView, $sel) $count = _GUICtrlListView_GetItemCount($ListView) - 1 If $sel > $count Then $sel = $count _GUICtrlListView_SetItemSelected($ListView, $sel, True, True) EndSelect EndSelect EndSelect $tagNMHDR = 0 $event = 0 $lParam = 0 EndFunc ;==>WM_Notify_Events Terenz 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now