Jump to content

Creat gui table and find data


 Share

Recommended Posts

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.

 

autoitscript.png

Edited by meomeo192
Link to comment
Share on other sites

  • Moderators

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:

#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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

meomeo192,

You have the data in an array, so use _ArraySearch on that array.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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

  • Moderators

meomeo192,

That is exactly how I would do it.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Please note that if the delimiter is a "|" in the file, there is maybe a simpler way

#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

 

Link to comment
Share on other sites

  • Moderators

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:

#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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • 4 years later...
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:

#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 as
https://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

NoMatchingEndFunction.jpg

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...