DJ VenGenCe Posted August 16, 2007 Share Posted August 16, 2007 (edited) Using the following code provided by gafrost (thank you) I would like to take this listview a step further. Sending the data to a new listview but only by the ones that are checked off. Pressing the button at the top will copy the data into the listview on the right. This is where I am stuck. Any Ideas? CODE;gafrost ;gafrost #include <GUIConstants.au3> ;Global Const $LVFI_PARAM = 0x0001 ;Global Const $LVIF_TEXT = 0x0001 ;Global Const $LVM_FIRST = 0x1000 Global Const $LVM_GETITEM = $LVM_FIRST + 5 ;Global Const $LVM_FINDITEM = $LVM_FIRST + 13 ;Global Const $LVM_SETSELECTEDCOLUMN = $LVM_FIRST + 140 Dim $nCurCol = -1 Dim $nSortDir = 1 Dim $bSet = 0 Dim $nCol = -1 $gui = GUICreate("TEST APP!", 640, 480, -1, -1) $copy = GUICtrlCreateButton("Copy Selected Fields", 10, 5, 100,17) $listview = GUICtrlCreateListView("Column 1|Column 2|Column3", 0, 50, 200, 200, $WS_VSCROLL, $LVS_EX_CHECKBOXES + $LVS_EX_GRIDLINES) GUICtrlRegisterListViewSort(-1, "LVSort") ; Register the function "SortLV" for the sorting callback GUICtrlCreateListViewItem("444|444|444", $listview) GUICtrlCreateListViewItem("333|333|333", $listview) GUICtrlCreateListViewItem("222|222|222", $listview) GUICtrlCreateListViewItem("111|111|111", $listview) GUISetState(@SW_SHOW, $gui) $output_listview = GUICtrlCreateListView("Column 1|Column 2|Column3", 250,50, 200, 200); While 1 $msg = GUIGetMsg() Select Case $msg = $copy ;do stuff Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $listview $bSet = 0 $nCurCol = $nCol GUICtrlSendMsg($listview, $LVM_SETSELECTEDCOLUMN, GUICtrlGetState($listview), 0) DllCall("user32.dll", "int", "InvalidateRect", "hwnd", GUICtrlGetHandle($listview), "int", 0, "int", 1) EndSelect WEnd ; Our sorting callback funtion Func LVSort($hWnd, $nItem1, $nItem2, $nColumn) Local $nSort ; Switch the sorting direction If $nColumn = $nCurCol Then If Not $bSet Then $nSortDir = $nSortDir * - 1 $bSet = 1 EndIf Else $nSortDir = 1 EndIf $nCol = $nColumn $val1 = GetSubItemText($listview, $nItem1, $nColumn) $val2 = GetSubItemText($listview, $nItem2, $nColumn) $nResult = 0 ; No change of item1 and item2 positions If $val1 < $val2 Then $nResult = -1 ; Put item2 before item1 ElseIf $val1 > $val2 Then $nResult = 1 ; Put item2 behind item1 EndIf $nResult = $nResult * $nSortDir Return $nResult EndFunc ;==>LVSort ; Retrieve the text of a listview item in a specified column Func GetSubItemText($nCtrlID, $nItemID, $nColumn) Local $stLvfi = DllStructCreate("uint;ptr;int;int[2];int") DllStructSetData($stLvfi, 1, $LVFI_PARAM) DllStructSetData($stLvfi, 3, $nItemID) Local $stBuffer = DllStructCreate("char[260]") $nIndex = GUICtrlSendMsg($nCtrlID, $LVM_FINDITEM, -1, DllStructGetPtr($stLvfi)); Local $stLvi = DllStructCreate("uint;int;int;uint;uint;ptr;int;int;int;int") DllStructSetData($stLvi, 1, $LVIF_TEXT) DllStructSetData($stLvi, 2, $nIndex) DllStructSetData($stLvi, 3, $nColumn) DllStructSetData($stLvi, 6, DllStructGetPtr($stBuffer)) DllStructSetData($stLvi, 7, 260) GUICtrlSendMsg($nCtrlID, $LVM_GETITEM, 0, DllStructGetPtr($stLvi)); $sItemText = DllStructGetData($stBuffer, 1) $stLvi = 0 $stLvfi = 0 $stBuffer = 0 Return $sItemText EndFunc ;==>GetSubItemText Edited August 16, 2007 by DJ VenGenCe Link to comment Share on other sites More sharing options...
martin Posted August 17, 2007 Share Posted August 17, 2007 Using the following code provided by gafrost (thank you) I would like to take this listview a step further. Sending the data to a new listview but only by the ones that are checked off. Pressing the button at the top will copy the data into the listview on the right. This is where I am stuck. Any Ideas? CODE;gafrost ;gafrost #include <GUIConstants.au3> ;Global Const $LVFI_PARAM = 0x0001 ;Global Const $LVIF_TEXT = 0x0001 ;Global Const $LVM_FIRST = 0x1000 Global Const $LVM_GETITEM = $LVM_FIRST + 5 ;Global Const $LVM_FINDITEM = $LVM_FIRST + 13 ;Global Const $LVM_SETSELECTEDCOLUMN = $LVM_FIRST + 140 Dim $nCurCol = -1 Dim $nSortDir = 1 Dim $bSet = 0 Dim $nCol = -1 $gui = GUICreate("TEST APP!", 640, 480, -1, -1) $copy = GUICtrlCreateButton("Copy Selected Fields", 10, 5, 100,17) $listview = GUICtrlCreateListView("Column 1|Column 2|Column3", 0, 50, 200, 200, $WS_VSCROLL, $LVS_EX_CHECKBOXES + $LVS_EX_GRIDLINES) GUICtrlRegisterListViewSort(-1, "LVSort") ; Register the function "SortLV" for the sorting callback GUICtrlCreateListViewItem("444|444|444", $listview) GUICtrlCreateListViewItem("333|333|333", $listview) GUICtrlCreateListViewItem("222|222|222", $listview) GUICtrlCreateListViewItem("111|111|111", $listview) GUISetState(@SW_SHOW, $gui) $output_listview = GUICtrlCreateListView("Column 1|Column 2|Column3", 250,50, 200, 200); While 1 $msg = GUIGetMsg() Select Case $msg = $copy ;do stuff Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $listview $bSet = 0 $nCurCol = $nCol GUICtrlSendMsg($listview, $LVM_SETSELECTEDCOLUMN, GUICtrlGetState($listview), 0) DllCall("user32.dll", "int", "InvalidateRect", "hwnd", GUICtrlGetHandle($listview), "int", 0, "int", 1) EndSelect WEnd ; Our sorting callback funtion Func LVSort($hWnd, $nItem1, $nItem2, $nColumn) Local $nSort ; Switch the sorting direction If $nColumn = $nCurCol Then If Not $bSet Then $nSortDir = $nSortDir * - 1 $bSet = 1 EndIf Else $nSortDir = 1 EndIf $nCol = $nColumn $val1 = GetSubItemText($listview, $nItem1, $nColumn) $val2 = GetSubItemText($listview, $nItem2, $nColumn) $nResult = 0 ; No change of item1 and item2 positions If $val1 < $val2 Then $nResult = -1 ; Put item2 before item1 ElseIf $val1 > $val2 Then $nResult = 1 ; Put item2 behind item1 EndIf $nResult = $nResult * $nSortDir Return $nResult EndFunc ;==>LVSort ; Retrieve the text of a listview item in a specified column Func GetSubItemText($nCtrlID, $nItemID, $nColumn) Local $stLvfi = DllStructCreate("uint;ptr;int;int[2];int") DllStructSetData($stLvfi, 1, $LVFI_PARAM) DllStructSetData($stLvfi, 3, $nItemID) Local $stBuffer = DllStructCreate("char[260]") $nIndex = GUICtrlSendMsg($nCtrlID, $LVM_FINDITEM, -1, DllStructGetPtr($stLvfi)); Local $stLvi = DllStructCreate("uint;int;int;uint;uint;ptr;int;int;int;int") DllStructSetData($stLvi, 1, $LVIF_TEXT) DllStructSetData($stLvi, 2, $nIndex) DllStructSetData($stLvi, 3, $nColumn) DllStructSetData($stLvi, 6, DllStructGetPtr($stBuffer)) DllStructSetData($stLvi, 7, 260) GUICtrlSendMsg($nCtrlID, $LVM_GETITEM, 0, DllStructGetPtr($stLvi)); $sItemText = DllStructGetData($stBuffer, 1) $stLvi = 0 $stLvfi = 0 $stBuffer = 0 Return $sItemText EndFunc ;==>GetSubItemText You need to add this line to the start of your script #include <guilistview.au3> Then the case statement would be like this Case $msg = $copy For $n = _0 to GUICtrlListViewGetItemCount($listview) -1 If _GUICtrlListViewGetCheckedState($listview,$n) Then _GUICtrlListViewCopyItems ($listview,$output_listview, 0) EndIf Next You might need to add something to stop the same items being copied more than once. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. 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