Loc Posted August 1, 2020 Share Posted August 1, 2020 This is me again. Allow me to ask this question a second time. I have 1 Guilistview, it has 3 columns and many rows. I want to save to txt file, for example: Column 1 | Column 2 | Column 3 Its row will be sorted by, for example, the first row of column 1 starts each character, the row of column 2 will start counting from row 1 column is 10 characters, row 3 then counting from columns 1 and 2 is 20 characters. Characters here are all characters, signs, numbers, ... Is it possible to do so? Here is the image I found without the code Link to comment Share on other sites More sharing options...
Dan_555 Posted August 1, 2020 Share Posted August 1, 2020 (edited) Hi. Well, how would i go, if i would need such thing ? I'll describe one case but let you write the code, is that ok ? I know how to get individual item and its subitems from the ListView. To make an aligned list, i need to let each individual column have an equal amount of letters/numbers. This is how would an aligned Text look like, 1 line, in theory: "........",".................","...........","......" and with multiple rows: "........",".................","...........","......" "........",".................","...........","......" "........",".................","...........","......" (p.s. to look good, i want to use a monospaced font, (set up in the text editor), which has the exact char width for each letter) So, what do i need to do, to get such result ? Lets say that the 1st column needs 6 chars (~ max). I read out the 1st item from the Listview. I separate the Columns into their own variables, or into an array I get the first column, and calculate the String Length. If the string contains the word "TCP", then the string length is 3 If the 1st column needs 6 chars, then all i need to do is to Subtract the wanted length, with the length of the string. 6-3=3 Then i would use _StringRepeat function, and add the missing spaces, either at the front or at the end of the temporary variable. (depending if the string would be left or right aligned) (p.s. centered is possible but needs a bit more of calculation) This would look like: "TCP " And that is the basic idea. Now i only need to make a few loops. The outer loop reads each of the Listview items, and the inner loop separates the row into columns, and calculates each column width. And adds the new text to the old variable: $str_out=$str_out & $tmp_collumn If i use arrays, then i can assign, for each # in the array (somewhere at the start) the individual needed width. When all of the colums have been added, i can save the str_out variable to a text file. And i set the $str_out variable to "" after saving it, to have a fresh empty string in the next loop. (of course this is all written without the AutoIt's text formatting function) Edited August 1, 2020 by Dan_555 Some of my script sourcecode Link to comment Share on other sites More sharing options...
Loc Posted August 1, 2020 Author Share Posted August 1, 2020 I feel so shabby I couldn't sleep to wait for an answer. Thanks @ Dan_555 Link to comment Share on other sites More sharing options...
Dan_555 Posted August 1, 2020 Share Posted August 1, 2020 (edited) Well, you could give us at least something to start with: A ready Listview with added items etc etc. Here is an example, it does not save to a textfile, instead it displays the text in an edit field, with the right font selected: expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <MsgBoxConstants.au3> #include <String.au3> Example() Func Example() Local $aItem, $sText, $idListview #Region ### START Koda GUI section ### Form= $f1 = GUICreate("Listview format", 490, 279, 192, 125) $idListview = GUICtrlCreateListView("col1|col2|col3", 2, 2, 194, 268) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 50) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 50) $Edit1 = GUICtrlCreateEdit("", 205, 3, 278, 269) GUISetState(@SW_SHOW) GUICtrlSetFont ( $Edit1, 9 , 0 , 0 , "Courier", 1 ) #EndRegion ### END Koda GUI section ### GUICtrlCreateListViewItem("line1|data1|more1", $idListview) GUICtrlCreateListViewItem("li2|data2aasd|more2", $idListview) GUICtrlCreateListViewItem("line3|1234 23 |more3", $idListview) GUICtrlCreateListViewItem("line4|data4|more4", $idListview) GUICtrlCreateListViewItem("line5|data5|more5", $idListview) GUISetState(@SW_SHOW) Local $a_ColW[4] ;Define the column width array, we are using the numbers 1 to 3 (but skipping the 0) therefore its 4 items ! $a_ColW[1] = 6 ;Predefined column length, assumes that the text will not exceed these numbers $a_ColW[2] = 15 $a_ColW[3] = 15 For $x = 0 To _GUICtrlListView_GetItemCount($idListview) ;Outer Loop $aItem = _GUICtrlListView_GetItemTextArray($idListview, $x) ;Extract the columns into array For $i = 1 To $aItem[0] ;Inner Loop $sText = $sText & $aItem[$i] & _StringRepeat(" ",($a_ColW[$i]-StringLen($aItem[$i])+1)) ;Assemble the text Next WriteEdit($Edit1,$sText,0) ;Paste the formated text into the edit field $sText="" Next ; Loop until the user exits. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>Example Func WriteEdit($ed, $sMessage = "", $clear = 1) If $clear = 1 Then GUICtrlSetData($ed, "") GUICtrlSetData($ed, $sMessage & @CRLF , $clear) EndFunc ;==>WriteEdit I had to use a script from Autoit help file and to modify it a bit. Edited August 1, 2020 by Dan_555 Correcting spelling errors or typos Loc 1 Some of my script sourcecode Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 2, 2020 Moderators Share Posted August 2, 2020 Moved to the appropriate forum. Moderation Team 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...
TheXman Posted August 2, 2020 Share Posted August 2, 2020 (edited) Here is a slightly modified version of @Dan_555's example. It uses the StringFormat function. I think this was suggested in one of @Loc's previous topics. Using StringFormat seems a little easier to modify and maintain because it eliminates the need to calculate column widths, right-alignment, or decimal point alignment. Another possible benefit is that it will automatically round floating point numbers to the specified decimal place (see line3). expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <MsgBoxConstants.au3> #include <String.au3> Example() Func Example() Local $sText, $Edit1, $idListview, $Row #Region ### START Koda GUI section ### Form= GUICreate("Listview format", 520, 279, 192, 125) $idListview = GUICtrlCreateListView("col1|col2|col3", 2, 2, 194, 268) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 50) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 50) $Edit1 = GUICtrlCreateEdit("", 205, 3, 300, 269) GUICtrlSetFont ( $Edit1, 9 , 0 , 0 , "Courier", 1 ) #EndRegion ### END Koda GUI section ### GUICtrlCreateListViewItem("line1|data1|1.25" , $idListview) GUICtrlCreateListViewItem("li2|data2aasd|33.55", $idListview) GUICtrlCreateListViewItem("line3|data3|5.325" , $idListview) GUICtrlCreateListViewItem("line4|data4|18.99" , $idListview) GUICtrlCreateListViewItem("line5|data5|0" , $idListview) ;Process each row of the listview For $Row = 0 To _GUICtrlListView_GetItemCount($idListview) - 1 $sText = StringFormat("%-10s %-12s %8.2f", _ _GUICtrlListView_GetItemText($idListview, $Row, 0), _ _GUICtrlListView_GetItemText($idListview, $Row, 1), _ _GUICtrlListView_GetItemText($idListview, $Row, 2)) GUICtrlSetData($Edit1, $sText & @CRLF, 1) Next GUISetState(@SW_SHOW) ; Loop until the user exits. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE EndFunc ;==>Example Edited August 2, 2020 by TheXman aesthetic modifications to the script CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
Loc Posted August 3, 2020 Author Share Posted August 3, 2020 I am Vietnamese. So the text in my listview is accented. When it came out counting the whole sign, I didn't know if there was a way to fix it anymore. Words in unsigned English are possible. I have now discovered the error of my previous questions expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <MsgBoxConstants.au3> #include <String.au3> Example() Func Example() Local $aItem, $sText, $idListview #Region ### START Koda GUI section ### Form= $f1 = GUICreate("Listview format", 490, 279, 192, 125) $idListview = GUICtrlCreateListView("col1|col2|col3", 2, 2, 194, 268) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 50) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 50) $Edit1 = GUICtrlCreateEdit("", 205, 3, 278, 269) GUISetState(@SW_SHOW) GUICtrlSetFont ( $Edit1, 9 , 0 , 0 , "Courier", 1 ) #EndRegion ### END Koda GUI section ### GUICtrlCreateListViewItem("line1|Đất nước|more1", $idListview) GUICtrlCreateListViewItem("li2|Việt Nam Tôi|more2", $idListview) GUICtrlCreateListViewItem("line3|1234 23 |more3", $idListview) GUICtrlCreateListViewItem("line4|da ta4|more4", $idListview) GUICtrlCreateListViewItem("line5|data5|more5", $idListview) GUISetState(@SW_SHOW) Local $a_ColW[4] ;Define the column width array, we are using the numbers 1 to 3 (but skipping the 0) therefore its 4 items ! $a_ColW[1] = 6 ;Predefined column length, assumes that the text will not exceed these numbers $a_ColW[2] = 20 $a_ColW[3] = 20 For $x = 0 To _GUICtrlListView_GetItemCount($idListview) ;Outer Loop $aItem = _GUICtrlListView_GetItemTextArray($idListview, $x) ;Extract the columns into array For $i = 1 To $aItem[0] ;Inner Loop $sText = $sText & $aItem[$i] & _StringRepeat(" ",($a_ColW[$i]-StringLen($aItem[$i])+1)) ;Assemble the text Next WriteEdit($Edit1,$sText,0) ;Paste the formated text into the edit field $sText="" Next ; Loop until the user exits. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>Example Func WriteEdit($ed, $sMessage = "", $clear = 1) If $clear = 1 Then GUICtrlSetData($ed, "") GUICtrlSetData($ed, $sMessage & @CRLF , $clear) EndFunc ;==>WriteEdit Link to comment Share on other sites More sharing options...
Loc Posted August 5, 2020 Author Share Posted August 5, 2020 Asking permission to do outstanding work to get help Link to comment Share on other sites More sharing options...
Dan_555 Posted August 5, 2020 Share Posted August 5, 2020 (edited) Well, the problem is, that, if i copy and paste your accented text into the editor, it is displayed as: Quote GUICtrlCreateListViewItem("line1|Ðâ´t nuo´c|more1", $idListview) GUICtrlCreateListViewItem("li2|Viê?t Nam Tôi|more2", $idListview) so i can't help, as i do not have the vietnamese text support installed here. Edited August 5, 2020 by Dan_555 Some of my script sourcecode Link to comment Share on other sites More sharing options...
Zedna Posted August 7, 2020 Share Posted August 7, 2020 (edited) Try to convert text inside _StringRepeat(... StringLen(text) ...) by _WinAPI_WideCharToMultiByte() or _WinAPI_MultiByteToWideChar() EDIT: There is nice example in HelpFile for the function _WinAPI_WideCharToMultiByte() https://www.autoitscript.com/autoit3/docs/libfunctions/_WinAPI_WideCharToMultiByte.htm Edited August 7, 2020 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Loc Posted August 8, 2020 Author Share Posted August 8, 2020 Can someone see me. Can you give me an example of text editing in listview? Current topic I don't :( This is my new code that uses input and buttons to edit listview #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $GUI_Main = GUICreate("SELL", 562, 327, 386, 141) GUICtrlCreateLabel("Name of dish", 8, 24, 70, 17) $Input_Name = GUICtrlCreateInput("", 80, 24, 113, 21) GUICtrlCreateLabel("Price", 230, 24, 50, 17) $Input_Price = GUICtrlCreateInput("", 280, 24, 129, 21) $Button_Edit = GUICtrlCreateButton("EDIT", 440, 24, 105, 25) $ListView_Sell = GUICtrlCreateListView("Name of dish|Price", 0, 64, 561, 257) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 300) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 250) $ListViewItem_Sellone = GUICtrlCreateListViewItem("Stir-fried noodles with beef|35$", $ListView_Sell) $ListViewItem_Selltwo = GUICtrlCreateListViewItem("Fried fish ball|10$", $ListView_Sell) $ListViewItem_Sellthree = GUICtrlCreateListViewItem("goby hotpot|50$", $ListView_Sell) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $Button_Edit _EditListView() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _EditListView() EndFunc Link to comment Share on other sites More sharing options...
Dan_555 Posted August 8, 2020 Share Posted August 8, 2020 (edited) Text editing directly in the ListView can be done with GuiListView Ex. (the download link is in the 1st post.) I assume (knowing your previous thread, about calculating in the listview) that you do not use Arrays to hold and to save the data. Edited August 8, 2020 by Dan_555 Some of my script sourcecode Link to comment Share on other sites More sharing options...
Loc Posted August 8, 2020 Author Share Posted August 8, 2020 Yes. I need an example for my old theme Link to comment Share on other sites More sharing options...
Dan_555 Posted August 8, 2020 Share Posted August 8, 2020 (edited) Yes, but, you have to decide which data should be preferred. The data from the Array or the data from the ListView. Because if you change the data in the ListView, it is not automatically updated in the Array. The same is with the Array, if you modify the Array, the data is not automatically updated in the ListView. Until you update it. So here is the answer, on how to edit a Listview. There are few ways of doing it, and so i have chosen this one (without array) : expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> $GUI_Main = GUICreate("SELL", 562, 327, 386, 141) GUICtrlCreateLabel("Name of dish", 8, 24, 70, 17) $Input_Name = GUICtrlCreateInput("", 80, 24, 113, 21) GUICtrlCreateLabel("Price", 230, 24, 50, 17) $Input_Price = GUICtrlCreateInput("", 280, 24, 129, 21) $Button_Edit = GUICtrlCreateButton("Save", 440, 24, 105, 25) $ListView_Sell = GUICtrlCreateListView("Name of dish|Price", 0, 64, 561, 257) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 300) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 250) $ListViewItem_Sellone = GUICtrlCreateListViewItem("Stir-fried noodles with beef|35$", $ListView_Sell) $ListViewItem_Selltwo = GUICtrlCreateListViewItem("Fried fish ball|10$", $ListView_Sell) $ListViewItem_Sellthree = GUICtrlCreateListViewItem("goby hotpot|50$", $ListView_Sell) GUISetState(@SW_SHOW) Global $fClick = 0, $iLV, $iRow, $iCol Global $itemEdited=-1 GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY_Handler") $hLV_1_Handle = GUICtrlGetHandle($ListView_Sell) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $Button_Edit if $itemEdited>-1 Then _GUICtrlListView_SetItemText($ListView_Sell,$itemEdited,GuiCtrlRead($Input_Name)) _GUICtrlListView_SetItemText($ListView_Sell,$itemEdited,GuiCtrlRead($Input_Price),1) ;~ GUICtrlSetData($Input_Name, "") ;~ GUICtrlSetData($Input_Price, "") ;~ $itemEdited=-1 ;~ _GUICtrlListView_SetItemSelected($ListView_Sell,-1,False) EndIf Case $GUI_EVENT_CLOSE Exit EndSwitch If $fClick Then ; Display result ConsoleWrite("Clicked LV: " & @TAB & $iLV & " Row: " & @TAB & $iRow & " Col: " & @TAB & $iCol & @CRLF) If $iRow > -1 Then $tmparray = _GUICtrlListView_GetItemTextArray($ListView_Sell, $iRow) If $tmparray[0] > 0 Then $itemEdited = $iRow GUICtrlSetData($Input_Name, $tmparray[1]) GUICtrlSetData($Input_Price, $tmparray[2]) EndIf $tmparray = "" EndIf ; Clear flag $fClick = 0 EndIf WEnd Func _WM_NOTIFY_Handler($hWnd, $iMsg, $wParam, $lParam) ;modified code from https://www.autoitscript.com/forum/topic/155607-how-to-detect-which-listview-was-clicked/ #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 Switch DllStructGetData($tStruct, 1) Case $hLV_1_Handle $iLV = 1 Case Else Return EndSwitch If BitAND(DllStructGetData($tStruct, 3), 0xFFFFFFFF) = $NM_CLICK Then $iRow = DllStructGetData($tStruct, 4) $iCol = DllStructGetData($tStruct, 5) ; Set flag $fClick = 1 EndIf EndFunc ;==>_WM_NOTIFY_Handler Click on a listview item to select it for editing, then change the text in the input boxes, and click on save to save it. Eventually, modify the Case $Button_Edit and remove comment from the commented lines to see a small change. Edited August 8, 2020 by Dan_555 robertocm and Loc 1 1 Some of my script sourcecode Link to comment Share on other sites More sharing options...
Loc Posted August 8, 2020 Author Share Posted August 8, 2020 thank you very much Link to comment Share on other sites More sharing options...
Nine Posted August 8, 2020 Share Posted August 8, 2020 6 hours ago, Loc said: thank you very much Yes you should. He has been programming free for yourself recently... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy 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