meomeo192 Posted April 23, 2016 Share Posted April 23, 2016 (edited) Hello all, I have a file data, example: data.txt which has content: Checked|Column 1|Column 2|Column 3|Column 4|Column 5|Column 6|Column 7|Column 8 ×|50.01.0001|160404134631346000|Other value|T3|alphachymotrypsin|Other value|C|alpha choay 4000IU ×|50.01.0003|160407154252435000|Other value|T2|Paracetamol|Other value|C|Acepron 250mg |50.01.0005|160415135700860000|Other value|T3|Acenocoumarol|Other value|D|Acenocumarol WPW 4mg |50.01.0006|160423064434487000|Other value|T3|Acetylcystein|Other value|D|Aceblue 100mg ×|50.01.0007|160430993168114000|Other value|T1|Acetylcystein|Other value|C|Aceblue 200mg I want creat a gui can view this content, have some column do not appear in gui (Column 3 and 6), column Checked can convert to Gui checkbox, and have a GUICtrlCreateEdit to input data, then find this data in all columns, return the rows have data (See image attach to clearer). Please give me some tips, suggests. Thank you very much, and sorry about my bad English. Edited April 23, 2016 by meomeo192 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 23, 2016 Moderators Share Posted April 23, 2016 meomeo192, You need to use a ListView to display the data - you can set certain column widths to zero so that they do not display and add checkboxes to the first column. The other controls you have there are standard. This should get you started: expandcollapse popup#include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <File.au3> #include <Array.au3> #include <GuiListView.au3> ; Create file $sFileName = "Data.txt" FileDelete($sFileName) $sString = "Checked|Column 1|Column 2|Column 3|Column 4|Column 5|Column 6|Column 7|Column 8" & @CRLF & _ "×|50.01.0001|160404134631346000|Other value|T3|alphachymotrypsin|Other value|C|alpha choay 4000IU" & @CRLF & _ "×|50.01.0003|160407154252435000|Other value|T2|Paracetamol|Other value|C|Acepron 250mg" & @CRLF & _ "|50.01.0005|160415135700860000|Other value|T3|Acenocoumarol|Other value|D|Acenocumarol WPW 4mg" & @CRLF & _ "|50.01.0006|160423064434487000|Other value|T3|Acetylcystein|Other value|D|Aceblue 100mg" & @CRLF & _ "×|50.01.0007|160430993168114000|Other value|T1|Acetylcystein|Other value|C|Aceblue 200mg" FileWrite($sFileName, $sString) ; Read file into a 2D array Local $aData _FileReadToArray($sFileName, $aData, $FRTA_NOCOUNT, "|") ; Create GUI $hGUI = GUICreate("Test", 800, 500) ; Create controls GUICtrlCreateLabel("Find:", 10, 30, 100, 20) $cInput = GUICtrlCreateInput("", 120, 30, 300, 20) $cSave = GUICtrlCreateButton("Save Check", 480, 10, 80, 20) $cFind = GUICtrlCreateButton("Find", 480, 30, 80, 20) $cFind8Only = GUICtrlCreateCheckbox(" Column 8 only", 600, 30, 200, 20) ; Create ListView $cListView = GUICtrlCreateListView("", 10, 100, 780, 300) _GUICtrlListView_SetExtendedListViewStyle($cListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_CHECKBOXES)) ; Add columns For $i = 0 To 8 _GUICtrlListView_AddColumn($cListView, $aData[0][$i], 100) Next ; Hide columns 3 & 6 _GUICtrlListView_HideColumn($cListView, 3) _GUICtrlListView_HideColumn($cListView, 6) ; Remove the header _ArrayDelete($aData, 0) ; Load the ListView with the data _GUICtrlListView_AddArray($cListView, $aData) ; Check the checkboxes to match the data For $i = 0 To _GUICtrlListView_GetItemCount($cListView) - 1 If $aData[$i][0] = "×" Then _GUICtrlListView_SetItemChecked($cListView, $i) _GUICtrlListView_SetItemText($cListView, $i, "") EndIf Next GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Please ask if you have any questions. M23 GuyFromNJo and meomeo192 2 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
mikell Posted April 23, 2016 Share Posted April 23, 2016 May I add ;.... _GUICtrlListView_SetColumnOrder ($cListView, "0|1|2|7|4|5|8|3|6") ; GUISetState() meomeo192 1 Link to comment Share on other sites More sharing options...
meomeo192 Posted April 23, 2016 Author Share Posted April 23, 2016 Thank Melba23 and mikell , it just have a little problem, how to find the rows have data input in GUICtrlCreateInput? Thank you very much. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 24, 2016 Moderators Share Posted April 24, 2016 meomeo192, You have the data in an array, so use _ArraySearch on that array. M23 meomeo192 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
meomeo192 Posted April 24, 2016 Author Share Posted April 24, 2016 Melba23, Okay, I thought about that, set a temp Array as orginal array $aData, then search, and headed the rows which has data find, then creat listview from this temp array (just get the headed rows), but i do not sure that this is the best way, please confirm for me. Thank you very much. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 24, 2016 Moderators Share Posted April 24, 2016 meomeo192, That is exactly how I would do it. M23 meomeo192 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
mikell Posted April 24, 2016 Share Posted April 24, 2016 (edited) meomeo192, You could also use _ArrayFindAll to get all the row indexes if the data to search exists in several rows $aResults = _ArrayFindAll ($aData, "acetyl", 0, 0, 0, 1, -1) _ArrayDisplay($aResults) Edited April 24, 2016 by mikell meomeo192 1 Link to comment Share on other sites More sharing options...
mikell Posted April 24, 2016 Share Posted April 24, 2016 Please note that if the delimiter is a "|" in the file, there is maybe a simpler way expandcollapse popup#include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <File.au3> #include <Array.au3> #include <GuiListView.au3> ; Create file $sFileName = "Data.txt" FileDelete($sFileName) $sString = "Checked|Column 1|Column 2|Column 3|Column 4|Column 5|Column 6|Column 7|Column 8" & @CRLF & _ "×|50.01.0001|160404134631346000|Other value|T3|alphachymotrypsin|Other value|C|alpha choay 4000IU" & @CRLF & _ "×|50.01.0003|160407154252435000|Other value|T2|Paracetamol|Other value|C|Acepron 250mg" & @CRLF & _ "|50.01.0005|160415135700860000|Other value|T3|Acenocoumarol|Other value|D|Acenocumarol WPW 4mg" & @CRLF & _ "|50.01.0006|160423064434487000|Other value|T3|Acetylcystein|Other value|D|Aceblue 100mg" & @CRLF & _ "×|50.01.0007|160430993168114000|Other value|T1|Acetylcystein|Other value|C|Aceblue 200mg" FileWrite($sFileName, $sString) ;============================================ ; Create array 1D $aData = StringRegExp(FileRead($sFileName), '\N+', 3) ; delete cols 3-6 and set order 0-1-2-7-4-5-8 For $i = 0 To UBound($aData)-1 $aData[$i] = StringRegExpReplace($aData[$i], '(?x)((?:.*?\|){3}) (.*?\|) ((?:.*?\|){2}) (.*?\|) (.*?\|) (.*)', "$1$5$3$6") Next ;_ArrayDisplay($aData) $column_titles = $aData[0] _ArrayDelete($aData, 0) ;============================================ ; Create GUI $hGUI = GUICreate("Test", 800, 500) ; Create controls GUICtrlCreateLabel("Find:", 10, 30, 100, 20) $cInput = GUICtrlCreateInput("", 120, 30, 300, 20) $cSave = GUICtrlCreateButton("Save Check", 480, 10, 80, 20) $cFind = GUICtrlCreateButton("Find", 480, 30, 80, 20) ; $cFind8Only = GUICtrlCreateCheckbox(" Column 8 only", 600, 30, 200, 20) $cReset = GUICtrlCreateButton("Reset", 680, 70, 80, 20) ; Create ListView $cListView = GUICtrlCreateListView($column_titles, 10, 100, 780, 300) _GUICtrlListView_SetExtendedListViewStyle($cListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_CHECKBOXES)) For $i = 1 to _GUICtrlListView_GetColumnCount($cListView) - 1 _GUICtrlListView_SetColumnWidth ($cListView, $i, 110) Next ; Create items _ResetListview() GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cFind $search = GuiCtrlRead($cInput) If $search = "" Then ContinueLoop $aResults = _ArrayFindAll ($aData, $search, 0, 0, 0, 1) If UBound($aResults) = 0 Then Msgbox(0,"", "no results found") ContinueLoop EndIf ; _ArrayDisplay($aResults) _GUICtrlListView_DeleteAllItems($cListView) For $i = 0 To UBound($aResults)-1 GUICtrlCreateListViewItem($aData[$aResults[$i]], $cListView) If StringLeft($aData[$aResults[$i]], 1) = "×" Then _GUICtrlListView_SetItemChecked($cListView, $i) _GUICtrlListView_SetItemText($cListView, $i, "") EndIf Next Case $cReset _GUICtrlListView_DeleteAllItems($cListView) _ResetListview() EndSwitch WEnd Func _ResetListview() For $i = 0 to UBound($aData)-1 GUICtrlCreateListViewItem($aData[$i], $cListView) If StringLeft($aData[$i], 1) = "×" Then ; Check the checkboxes to match the data _GUICtrlListView_SetItemChecked($cListView, $i) _GUICtrlListView_SetItemText($cListView, $i, "") EndIf Next EndFunc meomeo192 and robertocm 2 Link to comment Share on other sites More sharing options...
meomeo192 Posted April 26, 2016 Author Share Posted April 26, 2016 (edited) mikell, and Melba23, I want copy some data in Gui, so i want select the text in _GUICtrlListView_SetExtendedListViewStyle, this is imposible? (View image attach to clearer). Thank you very much. Edited April 26, 2016 by meomeo192 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 26, 2016 Moderators Share Posted April 26, 2016 meomeo192, I know of no way to copy directly from the ListView itself - but you can easily make a small dialog appear when an item is double-clicked: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #include <File.au3> #include <Array.au3> #include <GuiListView.au3> ; Create file $sFileName = "Data.txt" FileDelete($sFileName) $sString = "Checked|Column 1|Column 2|Column 3|Column 4|Column 5|Column 6|Column 7|Column 8" & @CRLF & _ "×|50.01.0001|160404134631346000|Other value|T3|alphachymotrypsin|Other value|C|alpha choay 4000IU" & @CRLF & _ "×|50.01.0003|160407154252435000|Other value|T2|Paracetamol|Other value|C|Acepron 250mg" & @CRLF & _ "|50.01.0005|160415135700860000|Other value|T3|Acenocoumarol|Other value|D|Acenocumarol WPW 4mg" & @CRLF & _ "|50.01.0006|160423064434487000|Other value|T3|Acetylcystein|Other value|D|Aceblue 100mg" & @CRLF & _ "×|50.01.0007|160430993168114000|Other value|T1|Acetylcystein|Other value|C|Aceblue 200mg" FileWrite($sFileName, $sString) ; Read file into a 2D array Local $aData _FileReadToArray($sFileName, $aData, $FRTA_NOCOUNT, "|") ; Create GUI $hGUI = GUICreate("Test", 800, 500) ; Create controls GUICtrlCreateLabel("Find:", 10, 30, 100, 20) $cInput = GUICtrlCreateInput("", 120, 30, 300, 20) $cSave = GUICtrlCreateButton("Save Check", 480, 10, 80, 20) $cFind = GUICtrlCreateButton("Find", 480, 30, 80, 20) $cFind8Only = GUICtrlCreateCheckbox(" Column 8 only", 600, 30, 200, 20) ; Create ListView $cListView = GUICtrlCreateListView("", 10, 100, 780, 300) _GUICtrlListView_SetExtendedListViewStyle($cListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_CHECKBOXES)) ; Add columns For $i = 0 To 8 _GUICtrlListView_AddColumn($cListView, $aData[0][$i], 100) Next ; Hide columns 3 & 6 _GUICtrlListView_HideColumn($cListView, 3) _GUICtrlListView_HideColumn($cListView, 6) ; Remove the header _ArrayDelete($aData, 0) ; Load the ListView with the data _GUICtrlListView_AddArray($cListView, $aData) ; Check the checkboxes to match the data For $i = 0 To _GUICtrlListView_GetItemCount($cListView) - 1 If $aData[$i][0] = "×" Then _GUICtrlListView_SetItemChecked($cListView, $i) _GUICtrlListView_SetItemText($cListView, $i, "") EndIf Next $cDummy = GUICtrlCreateDummy() GUISetState() GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cDummy $hDialog = GUICreate("Double Clicked Item", 300, 100) $cLabel = GUICtrlCreateEdit(GUICtrlRead($cDummy), 10, 10, 280, 80) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd GUIDelete($hDialog) EndSwitch WEnd Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam ; Struct = $tagNMHDR and "int Item;int SubItem" from $tagNMLISTVIEW Local $tStruct = DllStructCreate("hwnd;uint_ptr;int_ptr;int;int", $lParam) If @error Then Return Local $iRow = DllStructGetData($tStruct, 4) Local $iColumn = DllStructGetData($tStruct, 5) Local $iCode = BitAND(DllStructGetData($tStruct, 3), 0xFFFFFFFF) Switch $iCode Case $NM_DBLCLK $sText = _GUICtrlListView_GetItemText($cListView, $iRow, $iColumn) GUICtrlSendToDummy($cDummy, $sText) EndSwitch EndFunc Now you can copy from the dialog. M23 meomeo192 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
AthanBit Posted October 8, 2020 Share Posted October 8, 2020 On 4/23/2016 at 11:05 PM, Melba23 said: meomeo192, You need to use a ListView to display the data - you can set certain column widths to zero so that they do not display and add checkboxes to the first column. The other controls you have there are standard. This should get you started: expandcollapse popup#include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <File.au3> #include <Array.au3> #include <GuiListView.au3> ; Create file $sFileName = "Data.txt" FileDelete($sFileName) $sString = "Checked|Column 1|Column 2|Column 3|Column 4|Column 5|Column 6|Column 7|Column 8" & @CRLF & _ "×|50.01.0001|160404134631346000|Other value|T3|alphachymotrypsin|Other value|C|alpha choay 4000IU" & @CRLF & _ "×|50.01.0003|160407154252435000|Other value|T2|Paracetamol|Other value|C|Acepron 250mg" & @CRLF & _ "|50.01.0005|160415135700860000|Other value|T3|Acenocoumarol|Other value|D|Acenocumarol WPW 4mg" & @CRLF & _ "|50.01.0006|160423064434487000|Other value|T3|Acetylcystein|Other value|D|Aceblue 100mg" & @CRLF & _ "×|50.01.0007|160430993168114000|Other value|T1|Acetylcystein|Other value|C|Aceblue 200mg" FileWrite($sFileName, $sString) ; Read file into a 2D array Local $aData _FileReadToArray($sFileName, $aData, $FRTA_NOCOUNT, "|") ; Create GUI $hGUI = GUICreate("Test", 800, 500) ; Create controls GUICtrlCreateLabel("Find:", 10, 30, 100, 20) $cInput = GUICtrlCreateInput("", 120, 30, 300, 20) $cSave = GUICtrlCreateButton("Save Check", 480, 10, 80, 20) $cFind = GUICtrlCreateButton("Find", 480, 30, 80, 20) $cFind8Only = GUICtrlCreateCheckbox(" Column 8 only", 600, 30, 200, 20) ; Create ListView $cListView = GUICtrlCreateListView("", 10, 100, 780, 300) _GUICtrlListView_SetExtendedListViewStyle($cListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_CHECKBOXES)) ; Add columns For $i = 0 To 8 _GUICtrlListView_AddColumn($cListView, $aData[0][$i], 100) Next ; Hide columns 3 & 6 _GUICtrlListView_HideColumn($cListView, 3) _GUICtrlListView_HideColumn($cListView, 6) ; Remove the header _ArrayDelete($aData, 0) ; Load the ListView with the data _GUICtrlListView_AddArray($cListView, $aData) ; Check the checkboxes to match the data For $i = 0 To _GUICtrlListView_GetItemCount($cListView) - 1 If $aData[$i][0] = "×" Then _GUICtrlListView_SetItemChecked($cListView, $i) _GUICtrlListView_SetItemText($cListView, $i, "") EndIf Next GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Please ask if you have any questions. M23 I am trying to use the Code posted ashttps://www.autoitscript.com/forum/topic/182081-creat-gui-table-and-find-data/ ( https://www.autoitscript.com/forum/topic/182081-creat-gui-table-and-find-data/ ) as Function named Func tableListView() But for some reason I get the attched error message Kindly Help 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