Jump to content

GUICtrlCreateListView


yucatan
 Share

Recommended Posts

  • Moderators

yucatan,

Like this: :graduated:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#Include <GuiEdit.au3>

Global $fDblClk = 0, $fEdited = False
Global $hListView = 0, $hEdit, $hDC, $hBrush, $aHit
Global $iListView_ID, $sItemText, $sNewText ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Global $aLV_Handles[7]

Global $hGUI = GUICreate("Test", 600, 500)

For $i = 1 To 3
    For $j = 0 To 1
        $hListView = _GUICtrlListView_Create($hGUI, "Col 1", 2 + (200 * ($i - 1)), 2 + (200 * $j), 196, 196, BitOR($LVS_REPORT, $LVS_SINGLESEL, $WS_BORDER), $LVS_EX_FULLROWSELECT)
        _GUICtrlListView_SetExtendedListViewStyle($hListView, $LVS_EX_FULLROWSELECT)
        $aLV_Handles[$i + ($j * 3)] = $hListView
        _GUICtrlListView_AddColumn($hListView, "Col 2")
        _GUICtrlListView_AddColumn($hListView, "Col 3")
        ControlDisable($hGUI, "", HWnd(_GUICtrlListView_GetHeader($hListView)))
        _GUICtrlListView_SetColumnWidth($hListView, 0, 60)
        _GUICtrlListView_SetColumnWidth($hListView, 1, 60)
        _GUICtrlListView_SetColumnWidth($hListView, 2, $LVSCW_AUTOSIZE_USEHEADER)
        For $k = 1 To 4
            _GUICtrlListView_AddItem($hListView, "Item " & $i + ($j * 3) & $k)
            _GUICtrlListView_AddSubItem($hListView, $k - 1, "Sub " & $i + ($j * 3) & Chr(64 + $k), 1)
            _GUICtrlListView_AddSubItem($hListView, $k - 1, "Sub " & $i + ($j * 3) & Chr(77 + $k), 2)
        Next
    Next
Next

$hEdit = GUICtrlCreateEdit("", 10, 410, 580, 80)

; Create dummy control for the accelerator to action
$hAccel_Enter = GUICtrlCreateDummy() ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

GUISetState()

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

; Set accelerator for Enter to use if editing
Dim $aAccelKeys[1][2]=[["{ENTER}", $hAccel_Enter]] ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $hAccel_Enter
            _End_SubItemEdit()
    EndSwitch

    ; If an item was double clicked
    If $fDblClk Then
        $hListView = $aLV_Handles[$fDblClk]
        $iListView_ID = $fDblClk
        $aHit = _GUICtrlListView_SubItemHitTest($hListView)
        If $aHit[0] <> -1 Then
            _Start_ItemEdit()
        EndIf
        $fDblClk = 0
    EndIf

    If $fEdited Then
        $fEdited = False
        ConsoleWrite("ListView " & $iListView_ID & " : Row " & $aHit[0] + 1 & " : Col " & $aHit[1] + 1 & " has been altered to read: " & $sNewText & @CRLF) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    EndIf


WEnd

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $wParam
    Local $hWndFrom, $iCode, $tNMHDR

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")

    For $i = 1 To 6
        If $aLV_Handles[$i] = $hWndFrom Then
            Switch $iCode
                Case $NM_DBLCLK
                    $fDblClk = $i
            EndSwitch
            ExitLoop
        EndIf
    Next
    Return $GUI_RUNDEFMSG

EndFunc

Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)

    #forceref $hWnd, $Msg, $wParam
    Local $iCode = BitShift($wParam, 16)
    Switch $lParam
        Case $hEdit
            Switch $iCode
                Case $EN_KILLFOCUS
                    _End_SubItemEdit()
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

Func _Start_ItemEdit()

    $sItemText = _GUICtrlListView_GetItemText($hListView, $aHit[0], $aHit[1])
    Local $iLen = _GUICtrlListView_GetColumnWidth($hListView, $aHit[1])
    Local $aRect = _GUICtrlListView_GetSubItemRect($hListView, $aHit[0], $aHit[1])
    Local $aPos = WinGetPos($hListView)
    Local $tPoint = DllStructCreate("int X;int Y")
    DllStructSetData($tPoint, "X", $aPos[0])
    DllStructSetData($tPoint, "Y", $aPos[1])
    _WinAPI_ScreenToClient($hGUI, $tPoint)
    Local $iEdit_X = DllStructGetData($tPoint, "X") + $aRect[0]
    Local $iEdit_Y = DllStructGetData($tPoint, "Y") + $aRect[1]
    $hEdit = _GUICtrlEdit_Create($hGUI, $sItemText, $iEdit_X + 6, $iEdit_Y, $iLen - 7, 17, BitOR($WS_CHILD, $WS_VISIBLE, $ES_AUTOHSCROLL, $ES_LEFT))
    _GUICtrlEdit_SetSel($hEdit, 0, -1)
    _WinAPI_SetFocus($hEdit)
    $hDC = _WinAPI_GetWindowDC($hEdit)
    $hBrush = _WinAPI_CreateSolidBrush(0)
    Local $stRect = DllStructCreate("int;int;int;int")
    DllStructSetData($stRect, 1, $iLen + 10)
    DllStructSetData($stRect, 2, 0)
    DllStructSetData($stRect, 3, 0)
    DllStructSetData($stRect, 4, 17)
    DllCall("user32.dll", "int", "FrameRect", "hwnd", $hDC, "ptr", DllStructGetPtr($stRect), "hwnd", $hBrush)
    ; Set acclerator key
    GUISetAccelerators($aAccelKeys)
    
EndFunc

Func _End_SubItemEdit()

    $sNewText = _GUICtrlEdit_GetText($hEdit) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    If $sNewText <> $sItemText Then ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
        _GUICtrlListView_SetItemText($hListView, $aHit[0], $sNewText, $aHit[1]) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
        $fEdited = True
    EndIf
    _WinAPI_DeleteObject($hBrush)
    _WinAPI_ReleaseDC($hEdit, $hDC)
    _WinAPI_DestroyWindow($hEdit)
    $hListView = 0
    ; Clear accelerator key
    GUISetAccelerators(0)

EndFunc

You should know which lines to look for by now! :(

M23

Edit: Added the new value to the output.

Edited by Melba23

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

yucatan,

Our posted crossed - I have just edited the earlier post! :graduated:

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

yucatan,

Our posted crossed - I have just edited the earlier post! :graduated:

M23

hi thanks for ur quick response i shall work it out.

one more thing:D

$hListView = _GUICtrlListView_Create($hGUI, "Col 1", 2 + (200 * ($i - 1)), 2 + (200 * $j), 196, 196, BitOR($LVS_REPORT, $LVS_SINGLESEL, $WS_BORDER), $LVS_EX_FULLROWSELECT)
        _GUICtrlListView_SetExtendedListViewStyle($hListView, $LVS_EX_FULLROWSELECT)

i wanne resize and relocate my listview.

how can i do that i dont understand the rule.

i know that normaly i can

GUICtrlListView_Create($hWnd, $sHeaderText, $iX, $iY[, $iWidth = 150[, $iHeight = 150[, $iStyle = 0x0000000D[, $iExStyle = 0x00000000[, $fCoInit = False]]]]])

but i dont udnerstand how i should do this now bacause i used a * what does that means in autoit?

Link to comment
Share on other sites

  • Moderators

yucatan,

i wanne resize and relocate my listview

I do not understand. Do you want to change the size of your ListView within the GUI? Do you want to move the ListView around within the GUI using the mouse? :(

i used a * what does that means in autoit

I am afraid you have lost me again. :graduated:

Please post the code you are using then I might begin to understand what you are trying to do. :D

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

yucatan,

I do not understand. Do you want to change the size of your ListView within the GUI? Do you want to move the ListView around within the GUI using the mouse? :(

I am afraid you have lost me again. :graduated:

Please post the code you are using then I might begin to understand what you are trying to do. :D

M23

Hello M23.

i wanne make that if somebody clicks a tab i want to execute some code.

wich code i wanne execute depents on wich tab they click.

this is my code

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#Include <GuiEdit.au3>
#include <Date.au3>
#include <Array.au3>
Global $fDblClk = 0, $fEdited = False
Global $hListView = 0, $hEdit, $hDC, $hBrush, $aHit
Global $iListView_ID, $sItemText
Global $aLV_Handles[7]
Global $hGUI = GUICreate("Test", 900, 940)
global $i[60]
global $iweekindex[10]
global $weeknumber[100]
For $iIndex = 1 To 7
    $sdate = _DateAdd("d", (@WDAY*-1) + $iIndex + 1, @YEAR& "/" & @MON & "/" & @MDAY)
    $dateswich = StringSplit($sdate,"/")
    $iweekindex[$iIndex] = $dateswich[3] &" "& $dateswich[2] &" "& $dateswich[1]
Next

;GUICtrlCreateLabel("Maandag "& $iweekindex[1], 60, 5)
$tab = GUICtrlCreateTab(10, 10, 900, 900)
for $weeknumber = 1 to 52
$weeknumber = GUICtrlCreateTabItem("Week "& $weeknumber)
next
GUICtrlSetState(_WeekNumberISO() , $GUI_SHOW)

For $i = 1 To 3
    For $j = 0 To 1
        $hListView = _GUICtrlListView_Create($hGUI, "Bus", 2 + (300 * ($i - 1)), 50 + (440 * $j), 295, 396, BitOR($LVS_REPORT, $LVS_SINGLESEL, $WS_BORDER), $LVS_EX_FULLROWSELECT)
        _GUICtrlListView_SetExtendedListViewStyle($hListView, $LVS_EX_FULLROWSELECT)
        $aLV_Handles[$i + ($j * 3)] = $hListView
        _GUICtrlListView_AddColumn($hListView, "Monteur")
        _GUICtrlListView_AddColumn($hListView, "Klant en Project")
        _GUICtrlListView_AddColumn($hListView, "Wvb")
        ControlDisable($hGUI, "", HWnd(_GUICtrlListView_GetHeader($hListView)))
        _GUICtrlListView_SetColumnWidth($hListView, 0, 30)
        _GUICtrlListView_SetColumnWidth($hListView, 1, 60)
        _GUICtrlListView_SetColumnWidth($hListView, 2, 165)
        _GUICtrlListView_SetColumnWidth($hListView, 3, 40)
        ;_GUICtrlListView_SetColumnWidth($hListView, 2, $LVSCW_AUTOSIZE_USEHEADER)
        For $k = 1 To 4
            _GUICtrlListView_AddItem($hListView, "" & $i + ($j * 3) & $k)
            _GUICtrlListView_AddSubItem($hListView, $k - 1, "Sub " & $i + ($j * 3) & Chr(64 + $k), 1)
            _GUICtrlListView_AddSubItem($hListView, $k - 1, "Sub " & $i + ($j * 3) & Chr(77 + $k), 2)
        Next
    Next
Next
; Create dummy control for the accelerator to action
$hAccel_Enter = GUICtrlCreateDummy() ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

; Set accelerator for Enter to use if editing
Dim $aAccelKeys[1][2]=[["{ENTER}", $hAccel_Enter]] ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $hAccel_Enter ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            _End_SubItemEdit() ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
        case "week 45"
            ConsoleWrite("test")
    EndSwitch

    ; If an item was double clicked
    If $fDblClk Then
        $hListView = $aLV_Handles[$fDblClk]
        $iListView_ID = $fDblClk
        $aHit = _GUICtrlListView_SubItemHitTest($hListView)
        If $aHit[0] <> -1 Then
            _Start_ItemEdit()
        EndIf
        $fDblClk = 0
    EndIf

    If $fEdited Then
        $fEdited = False
        ConsoleWrite("ListView " & $iListView_ID & " : Row " & $aHit[0] + 1 & " : Col " & $aHit[1] + 1 & " has been altered" & @CRLF)
    EndIf


WEnd

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $wParam
    Local $hWndFrom, $iCode, $tNMHDR

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")

    For $i = 1 To 6
        If $aLV_Handles[$i] = $hWndFrom Then
            Switch $iCode
                Case $NM_DBLCLK
                    $fDblClk = $i
            EndSwitch
            ExitLoop
        EndIf
    Next
    Return $GUI_RUNDEFMSG

EndFunc

Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)

    #forceref $hWnd, $Msg, $wParam
    Local $iCode = BitShift($wParam, 16)
    Switch $lParam
        Case $hEdit
            Switch $iCode
                Case $EN_KILLFOCUS
                    _End_SubItemEdit()
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

Func _Start_ItemEdit()

    $sItemText = _GUICtrlListView_GetItemText($hListView, $aHit[0], $aHit[1])
    Local $iLen = _GUICtrlListView_GetColumnWidth($hListView, $aHit[1])
    Local $aRect = _GUICtrlListView_GetSubItemRect($hListView, $aHit[0], $aHit[1])
    Local $aPos = WinGetPos($hListView)
    Local $tPoint = DllStructCreate("int X;int Y")
    DllStructSetData($tPoint, "X", $aPos[0])
    DllStructSetData($tPoint, "Y", $aPos[1])
    _WinAPI_ScreenToClient($hGUI, $tPoint)
    Local $iEdit_X = DllStructGetData($tPoint, "X") + $aRect[0]
    Local $iEdit_Y = DllStructGetData($tPoint, "Y") + $aRect[1]
    $hEdit = _GUICtrlEdit_Create($hGUI, $sItemText, $iEdit_X + 6, $iEdit_Y, $iLen - 7, 17, BitOR($WS_CHILD, $WS_VISIBLE, $ES_AUTOHSCROLL, $ES_LEFT))
    _GUICtrlEdit_SetSel($hEdit, 0, -1)
    _WinAPI_SetFocus($hEdit)
    $hDC = _WinAPI_GetWindowDC($hEdit)
    $hBrush = _WinAPI_CreateSolidBrush(0)
    Local $stRect = DllStructCreate("int;int;int;int")
    DllStructSetData($stRect, 1, $iLen + 10)
    DllStructSetData($stRect, 2, 0)
    DllStructSetData($stRect, 3, 0)
    DllStructSetData($stRect, 4, 17)
    DllCall("user32.dll", "int", "FrameRect", "hwnd", $hDC, "ptr", DllStructGetPtr($stRect), "hwnd", $hBrush)
    ; Set acclerator key
    GUISetAccelerators($aAccelKeys) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

EndFunc

Func _End_SubItemEdit()

    Local $sText = _GUICtrlEdit_GetText($hEdit)
    If $sText <> $sItemText Then
        _GUICtrlListView_SetItemText($hListView, $aHit[0], $sText, $aHit[1])
        $fEdited = True
    EndIf
    _WinAPI_DeleteObject($hBrush)
    _WinAPI_ReleaseDC($hEdit, $hDC)
    _WinAPI_DestroyWindow($hEdit)
    $hListView = 0
    ; Clear accelerator key
    GUISetAccelerators(0) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

EndFunc
Link to comment
Share on other sites

  • Moderators

yucatan,

this is my code

Not sure I entirely agree with that statement..... :graduated:

If you want to know which tab was clicked, then just ask AutoIt to tell you: :D

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#Include <GuiEdit.au3>
#include <Date.au3>
#include <Array.au3>
#include <TabConstants.au3>

Global $fDblClk = 0, $fEdited = False
Global $hListView = 0, $hEdit, $hDC, $hBrush, $aHit
Global $iListView_ID, $sItemText
Global $aLV_Handles[7]
global $i[60]
global $iweekindex[10]
global $weeknumber[100]

For $iIndex = 1 To 7
    $sdate = _DateAdd("d", (@WDAY*-1) + $iIndex + 1, @YEAR& "/" & @MON & "/" & @MDAY)
    $dateswich = StringSplit($sdate,"/")
    $iweekindex[$iIndex] = $dateswich[3] &" "& $dateswich[2] &" "& $dateswich[1]
Next

Global $hGUI = GUICreate("Test", 900, 940)

;GUICtrlCreateLabel("Maandag "& $iweekindex[1], 60, 5)
$tab = GUICtrlCreateTab(10, 10, 880, 900, $TCS_MULTILINE) ; <<<<<<<<<<<<<<<<<<<<<< Show all tabs on several lines
$iTab_Adjust = GUICtrlCreateDummy() + 1 ; <<<<<<<<<<<<<<<<<<<<<<<<<<<< Used to convert tab ControlID to Week Number
for $weeknumber = 1 to 52
    $weeknumber = GUICtrlCreateTabItem("Week "& $weeknumber)
next
GUICtrlCreateTabItem("") ; <<<<<<<<<<<<<<<<<<<<<<<<<<<< Close the tab definition - IMPORTANT
GUICtrlSetState(_WeekNumberISO() , $GUI_SHOW)

For $i = 1 To 3
    For $j = 0 To 1
        $hListView = _GUICtrlListView_Create($hGUI, "Bus", 2 + (300 * ($i - 1)), 90 + (440 * $j), 295, 396, BitOR($LVS_REPORT, $LVS_SINGLESEL, $WS_BORDER), $LVS_EX_FULLROWSELECT)
        _GUICtrlListView_SetExtendedListViewStyle($hListView, $LVS_EX_FULLROWSELECT)
        $aLV_Handles[$i + ($j * 3)] = $hListView
        _GUICtrlListView_AddColumn($hListView, "Monteur")
        _GUICtrlListView_AddColumn($hListView, "Klant en Project")
        _GUICtrlListView_AddColumn($hListView, "Wvb")
        ControlDisable($hGUI, "", HWnd(_GUICtrlListView_GetHeader($hListView)))
        _GUICtrlListView_SetColumnWidth($hListView, 0, 30)
        _GUICtrlListView_SetColumnWidth($hListView, 1, 60)
        _GUICtrlListView_SetColumnWidth($hListView, 2, 165)
        _GUICtrlListView_SetColumnWidth($hListView, 3, 40)
        ;_GUICtrlListView_SetColumnWidth($hListView, 2, $LVSCW_AUTOSIZE_USEHEADER)
        For $k = 1 To 4
            _GUICtrlListView_AddItem($hListView, "" & $i + ($j * 3) & $k)
            _GUICtrlListView_AddSubItem($hListView, $k - 1, "Sub " & $i + ($j * 3) & Chr(64 + $k), 1)
            _GUICtrlListView_AddSubItem($hListView, $k - 1, "Sub " & $i + ($j * 3) & Chr(77 + $k), 2)
        Next
    Next
Next
; Create dummy control for the accelerator to action
$hAccel_Enter = GUICtrlCreateDummy()
GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

; Set accelerator for Enter to use if editing
Dim $aAccelKeys[1][2]=[["{ENTER}", $hAccel_Enter]]

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $hAccel_Enter
            _End_SubItemEdit()
        Case $tab ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< If a tab was clicked <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            ConsoleWrite(GUICtrlRead($tab) + $iTab_Adjust & @CRLF) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Write Week Number
    EndSwitch

    ; If an item was double clicked
    If $fDblClk Then
        $hListView = $aLV_Handles[$fDblClk]
        $iListView_ID = $fDblClk
        $aHit = _GUICtrlListView_SubItemHitTest($hListView)
        If $aHit[0] <> -1 Then
            _Start_ItemEdit()
        EndIf
        $fDblClk = 0
    EndIf

    If $fEdited Then
        $fEdited = False
        ConsoleWrite("ListView " & $iListView_ID & " : Row " & $aHit[0] + 1 & " : Col " & $aHit[1] + 1 & " has been altered" & @CRLF)
    EndIf


WEnd

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $wParam
    Local $hWndFrom, $iCode, $tNMHDR

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")

    For $i = 1 To 6
        If $aLV_Handles[$i] = $hWndFrom Then
            Switch $iCode
                Case $NM_DBLCLK
                    $fDblClk = $i
            EndSwitch
            ExitLoop
        EndIf
    Next
    Return $GUI_RUNDEFMSG

EndFunc

Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)

    #forceref $hWnd, $Msg, $wParam
    Local $iCode = BitShift($wParam, 16)
    Switch $lParam
        Case $hEdit
            Switch $iCode
                Case $EN_KILLFOCUS
                    _End_SubItemEdit()
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

Func _Start_ItemEdit()

    $sItemText = _GUICtrlListView_GetItemText($hListView, $aHit[0], $aHit[1])
    Local $iLen = _GUICtrlListView_GetColumnWidth($hListView, $aHit[1])
    Local $aRect = _GUICtrlListView_GetSubItemRect($hListView, $aHit[0], $aHit[1])
    Local $aPos = WinGetPos($hListView)
    Local $tPoint = DllStructCreate("int X;int Y")
    DllStructSetData($tPoint, "X", $aPos[0])
    DllStructSetData($tPoint, "Y", $aPos[1])
    _WinAPI_ScreenToClient($hGUI, $tPoint)
    Local $iEdit_X = DllStructGetData($tPoint, "X") + $aRect[0]
    Local $iEdit_Y = DllStructGetData($tPoint, "Y") + $aRect[1]
    $hEdit = _GUICtrlEdit_Create($hGUI, $sItemText, $iEdit_X + 6, $iEdit_Y, $iLen - 7, 17, BitOR($WS_CHILD, $WS_VISIBLE, $ES_AUTOHSCROLL, $ES_LEFT))
    _GUICtrlEdit_SetSel($hEdit, 0, -1)
    _WinAPI_SetFocus($hEdit)
    $hDC = _WinAPI_GetWindowDC($hEdit)
    $hBrush = _WinAPI_CreateSolidBrush(0)
    Local $stRect = DllStructCreate("int;int;int;int")
    DllStructSetData($stRect, 1, $iLen + 10)
    DllStructSetData($stRect, 2, 0)
    DllStructSetData($stRect, 3, 0)
    DllStructSetData($stRect, 4, 17)
    DllCall("user32.dll", "int", "FrameRect", "hwnd", $hDC, "ptr", DllStructGetPtr($stRect), "hwnd", $hBrush)
    ; Set acclerator key
    GUISetAccelerators($aAccelKeys)

EndFunc

Func _End_SubItemEdit()

    Local $sText = _GUICtrlEdit_GetText($hEdit)
    If $sText <> $sItemText Then
        _GUICtrlListView_SetItemText($hListView, $aHit[0], $sText, $aHit[1])
        $fEdited = True
    EndIf
    _WinAPI_DeleteObject($hBrush)
    _WinAPI_ReleaseDC($hEdit, $hDC)
    _WinAPI_DestroyWindow($hEdit)
    $hListView = 0
    ; Clear accelerator key
    GUISetAccelerators(0)

EndFunc

What happened to the moveable, resizable ListViews? Or are we leaving that for another day? :(

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

yucatan,

If you are still interested, I have posted an advanced script here. :graduated:

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

  • 1 month later...

yucatan,

If you are still interested, I have posted an advanced script here. :x

M23

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#Include <GuiEdit.au3>
#include <Date.au3>
#include <Array.au3>
#include <TabConstants.au3>

Global $fDblClk = 0, $fEdited = False
Global $hListView = 0, $hEdit, $hDC, $hBrush, $aHit
Global $iListView_ID, $sItemText
Global $aLV_Handles[7]
global $i[60]
global $iweekindex[10]
global $weeknumber[100]

For $iIndex = 1 To 7
    $sdate = _DateAdd("d", (@WDAY*-1) + $iIndex + 1, @YEAR& "/" & @MON & "/" & @MDAY)
    $dateswich = StringSplit($sdate,"/")
    $iweekindex[$iIndex] = $dateswich[3] &" "& $dateswich[2] &" "& $dateswich[1]
Next

Global $hGUI = GUICreate("Test", 900, 940)

GUICtrlCreateLabel("Maandag ", 60, 50)
$tab = GUICtrlCreateTab(10, 10, 880, 500) ; <<<<<<<<<<<<<<<<<<<<<< Show all tabs on several lines
$iTab_Adjust = GUICtrlCreateDummy() + 1 ; <<<<<<<<<<<<<<<<<<<<<<<<<<<< Used to convert tab ControlID to Week Number
for $weeknumber = 1 to 52
    $weeknumber = GUICtrlCreateTabItem("Week "& $weeknumber)
next
GUICtrlCreateTabItem("") ; <<<<<<<<<<<<<<<<<<<<<<<<<<<< Close the tab definition - IMPORTANT
GUICtrlSetState(_WeekNumberISO() , $GUI_SHOW)

For $i = 1 To 3
    For $j = 0 To 1
        $hListView = _GUICtrlListView_Create($hGUI, "Bus", 15 + (300 * ($i - 1)), 90 + (440 * $j), 270, 396, BitOR($LVS_REPORT, $LVS_SINGLESEL, $WS_BORDER), $LVS_EX_FULLROWSELECT)
        _GUICtrlListView_SetExtendedListViewStyle($hListView, $LVS_EX_FULLROWSELECT)
        $aLV_Handles[$i + ($j * 3)] = $hListView
        _GUICtrlListView_AddColumn($hListView, "Monteur")
        _GUICtrlListView_AddColumn($hListView, "Klant en Project")
        _GUICtrlListView_AddColumn($hListView, "Wvb")
        ControlDisable($hGUI, "", HWnd(_GUICtrlListView_GetHeader($hListView)))
        _GUICtrlListView_SetColumnWidth($hListView, 0, 30)
        _GUICtrlListView_SetColumnWidth($hListView, 1, 60)
        _GUICtrlListView_SetColumnWidth($hListView, 2, 165)
        _GUICtrlListView_SetColumnWidth($hListView, 3, 40)
        ;_GUICtrlListView_SetColumnWidth($hListView, 2, $LVSCW_AUTOSIZE_USEHEADER)
        For $k = 1 To 4
            _GUICtrlListView_AddItem($hListView, "" & $i + ($j * 3) & $k)
            _GUICtrlListView_AddSubItem($hListView, $k - 1, "Sub " & $i + ($j * 3) & Chr(64 + $k), 1)
            _GUICtrlListView_AddSubItem($hListView, $k - 1, "Sub " & $i + ($j * 3) & Chr(77 + $k), 2)
        Next
    Next
Next
; Create dummy control for the accelerator to action
$hAccel_Enter = GUICtrlCreateDummy()
GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

; Set accelerator for Enter to use if editing
Dim $aAccelKeys[1][2]=[["{ENTER}", $hAccel_Enter]]

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $hAccel_Enter
            _End_SubItemEdit()
        Case $tab ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< If a tab was clicked <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            ConsoleWrite(GUICtrlRead($tab) + $iTab_Adjust & @CRLF) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Write Week Number
    EndSwitch

    ; If an item was double clicked
    If $fDblClk Then
        $hListView = $aLV_Handles[$fDblClk]
        $iListView_ID = $fDblClk
        $aHit = _GUICtrlListView_SubItemHitTest($hListView)
        If $aHit[0] <> -1 Then
            _Start_ItemEdit()
        EndIf
        $fDblClk = 0
    EndIf

    If $fEdited Then
        $fEdited = False
        ConsoleWrite("ListView " & $iListView_ID & " : Row " & $aHit[0] + 1 & " : Col " & $aHit[1] + 1 & " has been altered" & @CRLF)
    EndIf


WEnd

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $wParam
    Local $hWndFrom, $iCode, $tNMHDR

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")

    For $i = 1 To 6
        If $aLV_Handles[$i] = $hWndFrom Then
            Switch $iCode
                Case $NM_DBLCLK
                    $fDblClk = $i
            EndSwitch
            ExitLoop
        EndIf
    Next
    Return $GUI_RUNDEFMSG

EndFunc

Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)

    #forceref $hWnd, $Msg, $wParam
    Local $iCode = BitShift($wParam, 16)
    Switch $lParam
        Case $hEdit
            Switch $iCode
                Case $EN_KILLFOCUS
                    _End_SubItemEdit()
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

Func _Start_ItemEdit()

    $sItemText = _GUICtrlListView_GetItemText($hListView, $aHit[0], $aHit[1])
    Local $iLen = _GUICtrlListView_GetColumnWidth($hListView, $aHit[1])
    Local $aRect = _GUICtrlListView_GetSubItemRect($hListView, $aHit[0], $aHit[1])
    Local $aPos = WinGetPos($hListView)
    Local $tPoint = DllStructCreate("int X;int Y")
    DllStructSetData($tPoint, "X", $aPos[0])
    DllStructSetData($tPoint, "Y", $aPos[1])
    _WinAPI_ScreenToClient($hGUI, $tPoint)
    Local $iEdit_X = DllStructGetData($tPoint, "X") + $aRect[0]
    Local $iEdit_Y = DllStructGetData($tPoint, "Y") + $aRect[1]
    $hEdit = _GUICtrlEdit_Create($hGUI, $sItemText, $iEdit_X + 6, $iEdit_Y, $iLen - 7, 17, BitOR($WS_CHILD, $WS_VISIBLE, $ES_AUTOHSCROLL, $ES_LEFT))
    _GUICtrlEdit_SetSel($hEdit, 0, -1)
    _WinAPI_SetFocus($hEdit)
    $hDC = _WinAPI_GetWindowDC($hEdit)
    $hBrush = _WinAPI_CreateSolidBrush(0)
    Local $stRect = DllStructCreate("int;int;int;int")
    DllStructSetData($stRect, 1, $iLen + 10)
    DllStructSetData($stRect, 2, 0)
    DllStructSetData($stRect, 3, 0)
    DllStructSetData($stRect, 4, 17)
    DllCall("user32.dll", "int", "FrameRect", "hwnd", $hDC, "ptr", DllStructGetPtr($stRect), "hwnd", $hBrush)
    ; Set acclerator key
    GUISetAccelerators($aAccelKeys)

EndFunc

Func _End_SubItemEdit()

    Local $sText = _GUICtrlEdit_GetText($hEdit)
    If $sText <> $sItemText Then
        _GUICtrlListView_SetItemText($hListView, $aHit[0], $sText, $aHit[1])
        $fEdited = True
    EndIf
    _WinAPI_DeleteObject($hBrush)
    _WinAPI_ReleaseDC($hEdit, $hDC)
    _WinAPI_DestroyWindow($hEdit)
    $hListView = 0
    ; Clear accelerator key
    GUISetAccelerators(0)

EndFunc

#include <Array.au3>
#include <Date.au3>
local $week[55][8]
$YearToEnd = @YEAR +2
$year = @year -2
$Month = '01'
$Day = '01'
$sDate = $year & "/" & $Month & "/" & $Day
$iIndex = 1
$iIndex2 = 1
$asDatePart = ""
$iTimePart = ""
$displayday = ""

While 1
    _DateTimeSplit($sDate, $asDatePart, $iTimePart)
    if $asDatePart[1] > $YearToEnd  Then ExitLoop
if  $iIndex2 > 52 then $iIndex2 = 1

   $Week_No = _WeekNumberISO($year, $asDatePart[2], $asDatePart[3])
    $Day_No = _DateToDayOfWeek($year, $asDatePart[2], $asDatePart[3])
    If $Week_No = $iIndex2 Then
        ;ConsoleWrite($sDate & " " & $Week_No & " " & _DateDayOfWeek($Day_No, 0) & " " & $asDatePart[3] & " " & _DateToMonth($asDatePart[2]) & @CRLF)

        if _DateDayOfWeek($Day_No, 0) = "Monday" then $displayday = "Maandag"
        if _DateDayOfWeek($Day_No, 0) = "Tuesday" then $displayday = "Dinsdag"
        if _DateDayOfWeek($Day_No, 0) = "Wensday" then $displayday = "Woensdag"
        if _DateDayOfWeek($Day_No, 0) = "Thursday" then $displayday = "Donderdag"
        if _DateDayOfWeek($Day_No, 0) = "Friday" then $displayday = "Vrijdag"
        if _DateDayOfWeek($Day_No, 0) = "Saturday" then $displayday = "Zaterdag"
        if _DateDayOfWeek($Day_No, 0) = "Sunday" then $displayday = "Zondag"

        if _DateToMonth($asDatePart[2]) = "January" then $displaymonth = "Januari"
        if _DateToMonth($asDatePart[2]) = "February" then $displaymonth = "Februari"
        if _DateToMonth($asDatePart[2]) = "March" then $displaymonth = "Maart"
        if _DateToMonth($asDatePart[2]) = "April" then $displaymonth = "April"
        if _DateToMonth($asDatePart[2]) = "May" then $displaymonth = "Mei"
        if _DateToMonth($asDatePart[2]) = "June" then $displaymonth = "Juni"
        if _DateToMonth($asDatePart[2]) = "July" then $displaymonth = "Juli"
        if _DateToMonth($asDatePart[2]) = "August" then $displaymonth = "Augustus"
        if _DateToMonth($asDatePart[2]) = "September" then $displaymonth = "September"
        if _DateToMonth($asDatePart[2]) = "October" then $displaymonth = "October"
        if _DateToMonth($asDatePart[2]) = "November" then $displaymonth = "November"
        if _DateToMonth($asDatePart[2]) = "December" then $displaymonth = "December"





        $week[$Week_No][0] = $displayday  &" "& $asDatePart[3] &" "& $displaymonth
        $week[$Week_No][1] = $displayday  &" "& StringRight(_DateAdd( 'd',1, $sDate), 1) &" "& $displaymonth
        $week[$Week_No][2] = $displayday  &" "& StringRight(_DateAdd( 'd',2, $sDate), 2) &" "& $displaymonth
        $week[$Week_No][3] = $displayday  &" "& StringRight(_DateAdd( 'd',3, $sDate), 2) &" "& $displaymonth
        $week[$Week_No][4] = $displayday  &" "& StringRight(_DateAdd( 'd',4, $sDate), 2) &" "& $displaymonth
        $week[$Week_No][5] = $displayday  &" "& StringRight(_DateAdd( 'd',4, $sDate), 2) &" "& $displaymonth
        $week[$Week_No][6] = $displayday  &" "& StringRight(_DateAdd( 'd',5, $sDate), 2) &" "& $displaymonth
        $week[$Week_No][7] = $displayday  &" "& StringRight(_DateAdd( 'd',6, $sDate), 2) &" "& $displaymonth


        $iIndex2 += 1
        EndIf
    $sDate = _DateAdd("d", $iIndex, $sDate )
WEnd
_ArrayDisplay($week, "Class List of Active Window")

this is my code now.

i'm having some questions.

how can i edit the space betweet listview 1 and listview 2

i want the listview as width as possible.

ofcourse not that they run into eatch.

but i want them inside the tab i created.

a second question.

this gui is used to view the weeks of the year.

and edit ofcourse.

now i have week 1 until 52.

but after week 52 there is nothing.

what i would like is a possibility to change year.

so when the end of 2010 is near like now.

that its possible to view week 1 of 2011 maby

unlimited arrows

so that i can right on the right arrow. until 2020

and when i click left that i can go back to 2000 for example.

i only dont know how i should create this.

some help or advice would be great.

the above script i use to calc with week contains wich 7 dates.

Thanks alot Greetz Yucatan

Edited by yucatan
Link to comment
Share on other sites

  • Moderators

yucatan,

i want the listview as width as possible. ofcourse not that they run into eatch

Then adjust the size and locations of the ListView sto fit: :shifty:

$hListView = _GUICtrlListView_Create($hGUI, "Bus", 15 + (290 * ($i - 1)), 90 + (440 * $j), 285, 406, BitOR($LVS_REPORT, $LVS_SINGLESEL, $WS_BORDER), $LVS_EX_FULLROWSELECT)

what i would like is a possibility to change year

And you seem to think I am going to code it for you! ;naughty:

I would suggets that you use an UpDown somewhere on your GUI from which you select the year. You would then keep the same 52 tabs, but the year they refer to would be determined by the value of the UpDown. :x

Give it a go yourself over the festive season - you know where we are if you run into problems. :P

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

yucatan,

Herer is an amended version of your "put all the days of the year into an ISO week array" function. It is bit faster than the original! :P

#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <UpdownConstants.au3>
#include <Array.au3>
#include <Date.au3>

Global $aWeeks[54][8]
$iYear = @YEAR + 1

$hGUI = GUICreate("Test", 500, 500)

$hInput = GUICtrlCreateInput($iYear, 10, 10, 50, 20, $ES_READONLY)
$hUpDown = GUICtrlCreateUpdown($hInput, BitOr($GUI_SS_DEFAULT_UPDOWN, $UDS_WRAP, $UDS_NOTHOUSANDS))
GUICtrlSetLimit($hUpDown, $iYear + 5, $iYear - 5)

$hButton = GUICtrlCreateButton("Calculate", 10, 50, 80, 30)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            $sYear = GUICtrlRead($hInput)
            _Calculate($sYear)
    EndSwitch

WEnd

Func _Calculate($sYear)

    ; Clear array
    Global $aWeeks[54][8]

    ; Set local variables
    Local $asDatePart, $iTimePart
    Local $aDays[8] = [7, "Maandag", "Dinsdag", "Woensdag", "Donderdag", "Vrijdag", "Zaterdag", "Zondag"]
    Local $aMonths[13] = [12, "Januari", "Februari", "Maart", "April", "Mei", "Juni", "Juli", "Augustus", "September", "October", "November", "December"]

    ; Set first day
    $sDate = $sYear & "/01/01"
    ; Set flag to indicate initial week
    $fStart = True

    While 1

        ; Split date
        _DateTimeSplit($sDate, $asDatePart, $iTimePart)
        ; Exit if past end required year
        If $asDatePart[1] > $sYear Then ExitLoop

        ; Get week number
        $iWeek = _WeekNumberISO($sYear, $asDatePart[2], $asDatePart[3])

        ; Adjust to cover final part of previous Week 52 if required
        If $fStart Then
            If $iWeek >= 52 Then $iWeek = 0
        Else
            If $iWeek = 1 Then $iWeek = 53
        EndIf
        ; Reset flag if past initial week
        If $iWeek = 2 Then $fStart = False

        ; Get day of week and adjust for Sunday
        $iIndex = _DateToDayOfWeek($sYear, $asDatePart[2], $asDatePart[3])
        If $iIndex = 1 Then
            $iIndex = 8
            ; Adjust for final week if needed
            If Not $fStart And $iWeek = 53 Then $iWeek = 52
        EndIf

        ; Fill array
        $aWeeks[$iWeek][$iIndex - 1] = $aDays[$iIndex - 1] & " " & $asDatePart[3] & " " & $aMonths[$asDatePart[2]]
        ; Move to next day
        $sDate = _DateAdd("d", 1, $sDate)

    WEnd

    _ArrayDisplay($aWeeks, $sYear)

EndFunc

It also shows how you might use an UpDown to choose the year as I suggest above. :x

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

Hello M23.

Thanks u for all ur help.

i'm still having some questions.

this is my code now.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#Include <GuiEdit.au3>
#include <Date.au3>
#include <Array.au3>
#include <TabConstants.au3>
#include <EditConstants.au3>
#include <UpdownConstants.au3>

Global $fDblClk = 0, $fEdited = False
Global $hListView = 0, $hEdit, $hDC, $hBrush, $aHit
Global $iListView_ID, $sItemText
Global $aLV_Handles[7]
global $i[60]
global $iweekindex[10]
global $weeknumber[100]
Global $aWeeks[54][8]
$iYear = @YEAR ;+ 1

For $iIndex = 1 To 7
    $sdate = _DateAdd("d", (@WDAY*-1) + $iIndex + 1, @YEAR& "/" & @MON & "/" & @MDAY)
    $dateswich = StringSplit($sdate,"/")
    $iweekindex[$iIndex] = $dateswich[3] &" "& $dateswich[2] &" "& $dateswich[1]
Next

Global $hGUI = GUICreate("Test", 900, 940)

$tab = GUICtrlCreateTab(10, 10, 890, 940) ; <<<<<<<<<<<<<<<<<<<<<< Show all tabs on several lines
$iTab_Adjust = GUICtrlCreateDummy() + 1 ; <<<<<<<<<<<<<<<<<<<<<<<<<<<< Used to convert tab ControlID to Week Number
for $weeknumber = 1 to 52
    $weeknumber = GUICtrlCreateTabItem("Week "& $weeknumber)
next
GUICtrlCreateTabItem("") ; <<<<<<<<<<<<<<<<<<<<<<<<<<<< Close the tab definition - IMPORTANT
GUICtrlSetState(_WeekNumberISO() , $GUI_SHOW)

$hInput = GUICtrlCreateInput($iYear, 420, 45, 50, 20, $ES_READONLY)
$hUpDown = GUICtrlCreateUpdown($hInput, BitOr($GUI_SS_DEFAULT_UPDOWN, $UDS_WRAP, $UDS_NOTHOUSANDS))
$sYear = GUICtrlRead($hInput)
$sDate = $sYear & "/01/01"
$fStart = True
GUICtrlSetLimit($hUpDown, $iYear + 5, $iYear - 5)

$monday = GUICtrlCreateLabel("", 60, 70,120,50)
$tuesday = GUICtrlCreateLabel("", 430, 70,120,50)
$wensday = GUICtrlCreateLabel("", 700, 70,120,50)
$thursday = GUICtrlCreateLabel("", 100, 500,130,50)
$friday = GUICtrlCreateLabel("", 430, 500,130,50)
$saterday = GUICtrlCreateLabel("", 700, 500,130,50)
$clickedweek = _WeekNumberISO()
_Calculate($syear)

For $i = 1 To 3
    For $j = 0 To 1
        $hListView = _GUICtrlListView_Create($hGUI, "Bus", 15 + (290 * ($i - 1)), 90 + (440 * $j), 299, 406, BitOR($LVS_REPORT, $LVS_SINGLESEL, $WS_BORDER), $LVS_EX_FULLROWSELECT)
        _GUICtrlListView_SetExtendedListViewStyle($hListView, $LVS_EX_FULLROWSELECT)
        $aLV_Handles[$i + ($j * 3)] = $hListView
        _GUICtrlListView_AddColumn($hListView, "Monteur")
        _GUICtrlListView_AddColumn($hListView, "Klant en Project")
        _GUICtrlListView_AddColumn($hListView, "Wvb")
        ControlDisable($hGUI, "", HWnd(_GUICtrlListView_GetHeader($hListView)))
        _GUICtrlListView_SetColumnWidth($hListView, 0, 30)
        _GUICtrlListView_SetColumnWidth($hListView, 1, 60)
        _GUICtrlListView_SetColumnWidth($hListView, 2, 155)
        _GUICtrlListView_SetColumnWidth($hListView, 3, 54)
        ;_GUICtrlListView_SetColumnWidth($hListView, 2, $LVSCW_AUTOSIZE_USEHEADER)
        For $k = 1 To 4
            _GUICtrlListView_AddItem($hListView, "" & $i + ($j * 3) & $k)
            _GUICtrlListView_AddSubItem($hListView, $k - 1, "Sub " & $i + ($j * 3) & Chr(64 + $k), 1)
            _GUICtrlListView_AddSubItem($hListView, $k - 1, "Sub " & $i + ($j * 3) & Chr(77 + $k), 2)
        Next
    Next
Next
; Create dummy control for the accelerator to action
$hAccel_Enter = GUICtrlCreateDummy()
GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")


; Set accelerator for Enter to use if editing
Dim $aAccelKeys[1][2]=[["{ENTER}", $hAccel_Enter]]

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $hAccel_Enter
            _End_SubItemEdit()
        Case $tab  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< If a tab was clicked <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            $sYear = GUICtrlRead($hInput)
            $fStart = True
            $clickedweek = (GUICtrlRead($tab) + $iTab_Adjust & " " & $sYear & @CRLF) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Write Week Number
            _Calculate($sYear)
        case $hUpDown
            $sYear = GUICtrlRead($hInput)
            $fStart = True
            $clickedweek = (GUICtrlRead($tab) + $iTab_Adjust & " " & $sYear & @CRLF) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Write Week Number
            _Calculate($sYear)
    EndSwitch



    ; If an item was double clicked
    If $fDblClk Then
        $hListView = $aLV_Handles[$fDblClk]
        $iListView_ID = $fDblClk
        $aHit = _GUICtrlListView_SubItemHitTest($hListView)
        If $aHit[0] <> -1 Then
            _Start_ItemEdit()
        EndIf
        $fDblClk = 0
    EndIf

    If $fEdited Then
        $fEdited = False
        ConsoleWrite("ListView " & $iListView_ID & " : Row " & $aHit[0] + 1 & " : Col " & $aHit[1] + 1 & " has been altered" & @CRLF)

   EndIf

WEnd

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $wParam
    Local $hWndFrom, $iCode, $tNMHDR

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")

    For $i = 1 To 6
        If $aLV_Handles[$i] = $hWndFrom Then
            Switch $iCode
                Case $NM_DBLCLK
                    $fDblClk = $i
            EndSwitch
            ExitLoop
        EndIf
    Next
    Return $GUI_RUNDEFMSG

EndFunc

Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)

    #forceref $hWnd, $Msg, $wParam
    Local $iCode = BitShift($wParam, 16)
    Switch $lParam
        Case $hEdit
            Switch $iCode
                Case $EN_KILLFOCUS
                    _End_SubItemEdit()
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

Func _Start_ItemEdit()

    $sItemText = _GUICtrlListView_GetItemText($hListView, $aHit[0], $aHit[1])
    Local $iLen = _GUICtrlListView_GetColumnWidth($hListView, $aHit[1])
    Local $aRect = _GUICtrlListView_GetSubItemRect($hListView, $aHit[0], $aHit[1])
    Local $aPos = WinGetPos($hListView)
    Local $tPoint = DllStructCreate("int X;int Y")
    DllStructSetData($tPoint, "X", $aPos[0])
    DllStructSetData($tPoint, "Y", $aPos[1])
    _WinAPI_ScreenToClient($hGUI, $tPoint)
    Local $iEdit_X = DllStructGetData($tPoint, "X") + $aRect[0]
    Local $iEdit_Y = DllStructGetData($tPoint, "Y") + $aRect[1]
    $hEdit = _GUICtrlEdit_Create($hGUI, $sItemText, $iEdit_X + 6, $iEdit_Y, $iLen - 7, 17, BitOR($WS_CHILD, $WS_VISIBLE, $ES_AUTOHSCROLL, $ES_LEFT))
    _GUICtrlEdit_SetSel($hEdit, 0, -1)
    _WinAPI_SetFocus($hEdit)
    $hDC = _WinAPI_GetWindowDC($hEdit)
    $hBrush = _WinAPI_CreateSolidBrush(0)
    Local $stRect = DllStructCreate("int;int;int;int")
    DllStructSetData($stRect, 1, $iLen + 10)
    DllStructSetData($stRect, 2, 0)
    DllStructSetData($stRect, 3, 0)
    DllStructSetData($stRect, 4, 17)
    DllCall("user32.dll", "int", "FrameRect", "hwnd", $hDC, "ptr", DllStructGetPtr($stRect), "hwnd", $hBrush)
    ; Set acclerator key
    GUISetAccelerators($aAccelKeys)

EndFunc

Func _End_SubItemEdit()

    Local $sText = _GUICtrlEdit_GetText($hEdit)
    If $sText <> $sItemText Then
        _GUICtrlListView_SetItemText($hListView, $aHit[0], $sText, $aHit[1])
        $fEdited = True
    EndIf
    _WinAPI_DeleteObject($hBrush)
    _WinAPI_ReleaseDC($hEdit, $hDC)
    _WinAPI_DestroyWindow($hEdit)
    $hListView = 0
    ; Clear accelerator key
    GUISetAccelerators(0)

EndFunc



Func _Calculate($sYear)

    ; Clear array
    Global $aWeeks[54][8]

    ; Set local variables
    Local $asDatePart, $iTimePart
    Local $aDays[8] = [7, "Maandag", "Dinsdag", "Woensdag", "Donderdag", "Vrijdag", "Zaterdag", "Zondag"]
    Local $aMonths[13] = [12, "Januari", "Februari", "Maart", "April", "Mei", "Juni", "Juli", "Augustus", "September", "October", "November", "December"]

    ; Set first day
    $sDate = $sYear & "/01/01"
    ; Set flag to indicate initial week
    $fStart = True

    While 1

        ; Split date
        _DateTimeSplit($sDate, $asDatePart, $iTimePart)
        ; Exit if past end required year
        If $asDatePart[1] > $sYear Then ExitLoop

        ; Get week number
        $iWeek = _WeekNumberISO($sYear, $asDatePart[2], $asDatePart[3])

        ; Adjust to cover final part of previous Week 52 if required
        If $fStart Then
            If $iWeek >= 52 Then $iWeek = 0
        Else
            If $iWeek = 1 Then $iWeek = 53
        EndIf
        ; Reset flag if past initial week
        If $iWeek = 2 Then $fStart = False

        ; Get day of week and adjust for Sunday
        $iIndex = _DateToDayOfWeek($sYear, $asDatePart[2], $asDatePart[3])
        If $iIndex = 1 Then
            $iIndex = 8
            ; Adjust for final week if needed
            If Not $fStart And $iWeek = 53 Then $iWeek = 52
        EndIf

        ; Fill array
        $aWeeks[$iWeek][$iIndex - 1] = $aDays[$iIndex - 1] & " " & $asDatePart[3] & " " & $aMonths[$asDatePart[2]]
        ; Move to next day
        $sDate = _DateAdd("d", 1, $sDate)
    WEnd
GUICtrlSetData($monday, $aWeeks[$clickedweek ][1])
GUICtrlSetData($tuesday, $aWeeks[$clickedweek ][2])
GUICtrlSetData($wensday, $aWeeks[$clickedweek ][3])
GUICtrlSetData($thursday, $aWeeks[$clickedweek ][4])
GUICtrlSetData($friday, $aWeeks[$clickedweek ][5])
GUICtrlSetData($saterday, $aWeeks[$clickedweek ][6])
EndFunc

my week number are not correct anymore.

it start at week 1 and then it go's to week 6.

i dont know why.

is it possible to dubbleclick on a emty rule in a listview and that i can create a new record?

how this should be done?

u see that i copied ur function _Calculate but is it possible to calculate with the days of one week instead of a year

if i say i wanne know the dates of week 40 of 2010

maby we or u can optimise the function that its only calculate the dates of one week.

then the func will be alot faster then it is now.

and secend maby u can test the code.

because it now very clear what is what week.

especialy when a year switch like now it upcoming then the weeknumbers arent fully correct.

thanks alot!

Edited by yucatan
Link to comment
Share on other sites

January 1, 2011 is on a Saturday, so of course it's going to show it that way. That is week one, and it's only 2 days long, anything else is just misreading the calendar.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • Moderators

yucatan,

Hello again! :D

Another pile of questions - here we go: :x

- 1. The weeks jumped from 1 to 6 because you did this:

for $weeknumber = 1 to 52
    $weeknumber = GUICtrlCreateTabItem("Week "& $weeknumber)
next

After the first tab was created, the value of $weeknumber was set to the value of the ControlID and not the loop variable. The solution is not to store the ControlIDs of the tabs - we can get the index by using GUICtrlRead which is enough for us. :lol:

- 2. You can only edit rows in ListView which actually exist. So we just need to add anough lines to fill the ListView (22 on my machine). I have still entered data so you can see the rows - for the finished article you just leave the items and subitems blank. :P

- 3. I have increased the speed of the script for you. You now only do the full calculation when you change the year - you must do it then to get the array filled! :( But now if all you do is change the week then you just read the existing array to reset the labels.

- 4. The week numbers are now correct. According to ISO, Week 1 is the first full week in the year, so I have added a Week 0 to cater for the times when there are a few days in the final week of the previous year. Similarly, there are times when you get the odd day in Week 53. However, I have arranged things so that the user cannot select these tabs unless there are days to display in those weeks - if the user tries to select Week 0 or 53 and there are no days in that week, the script automatically selects Weeks 1 or 52 instead. The same thing happens if the year is changed and the selected tab is set to one of those weeks which was valid in the previously selected year. :shifty:

Here is the modified script:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <GuiEdit.au3>
#include <Date.au3>
#include <Array.au3>
#include <TabConstants.au3>
#include <EditConstants.au3>
#include <UpdownConstants.au3>
#Include <GuiTab.au3>


Global $fDblClk = 0, $fEdited = False, $fWeek_0 = False, $fWeek_53 = False
Global $hListView = 0, $hEdit, $hDC, $hBrush, $aHit
Global $iListView_ID, $sItemText
Global $aLV_Handles[7]
Global $aWeeks[54][8]
Global $sYear = @YEAR
Global $sdate = $sYear & "/01/01"

Global $hGUI = GUICreate("Test", 900, 940)

$tab = GUICtrlCreateTab(10, 10, 890, 940)
$hTab_0 = GUICtrlCreateTabItem("Week 0")
For $weeknumber = 1 To 53
    GUICtrlCreateTabItem("Week " & $weeknumber)
Next
GUICtrlCreateTabItem("")

GUICtrlSetState(_WeekNumberISO() + $hTab_0, $GUI_SHOW)

$hInput = GUICtrlCreateInput($sYear, 420, 45, 50, 20, $ES_READONLY)
$hUpDown = GUICtrlCreateUpdown($hInput, BitOR($GUI_SS_DEFAULT_UPDOWN, $UDS_WRAP, $UDS_NOTHOUSANDS))
GUICtrlSetLimit($hUpDown, $sYear + 5, $sYear - 5)

$monday = GUICtrlCreateLabel("", 60, 70, 120, 50)
$tuesday = GUICtrlCreateLabel("", 430, 70, 120, 50)
$wednesday = GUICtrlCreateLabel("", 700, 70, 120, 50)
$thursday = GUICtrlCreateLabel("", 100, 500, 130, 50)
$friday = GUICtrlCreateLabel("", 430, 500, 130, 50)
$saturday = GUICtrlCreateLabel("", 700, 500, 130, 50)

_Calculate()

For $i = 1 To 3
    For $j = 0 To 1
        $hListView = _GUICtrlListView_Create($hGUI, "Bus", 15 + (290 * ($i - 1)), 90 + (440 * $j), 299, 406, BitOR($LVS_REPORT, $LVS_SINGLESEL, $WS_BORDER), $LVS_EX_FULLROWSELECT)
        _GUICtrlListView_SetExtendedListViewStyle($hListView, $LVS_EX_FULLROWSELECT)
        $aLV_Handles[$i + ($j * 3)] = $hListView
        _GUICtrlListView_AddColumn($hListView, "Monteur")
        _GUICtrlListView_AddColumn($hListView, "Klant en Project")
        _GUICtrlListView_AddColumn($hListView, "Wvb")
        ControlDisable($hGUI, "", HWnd(_GUICtrlListView_GetHeader($hListView)))
        _GUICtrlListView_SetColumnWidth($hListView, 0, 30)
        _GUICtrlListView_SetColumnWidth($hListView, 1, 60)
        _GUICtrlListView_SetColumnWidth($hListView, 2, 155)
        _GUICtrlListView_SetColumnWidth($hListView, 3, 1)
        ;_GUICtrlListView_SetColumnWidth($hListView, 2, $LVSCW_AUTOSIZE_USEHEADER)
        For $k = 1 To 22
            _GUICtrlListView_AddItem($hListView, "" & $i + ($j * 3) & $k)
            _GUICtrlListView_AddSubItem($hListView, $k - 1, "Sub " & $i + ($j * 3) & Chr(64 + $k), 1)
            _GUICtrlListView_AddSubItem($hListView, $k - 1, "Sub " & $i + ($j * 3) & Chr(77 + $k), 2)
        Next
    Next
Next

; Create dummy control for the accelerator to action
$hAccel_Enter = GUICtrlCreateDummy()
GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

; Set accelerator for Enter to use if editing
Dim $aAccelKeys[1][2] = [["{ENTER}", $hAccel_Enter]]

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $hAccel_Enter
            _End_SubItemEdit()
        Case $tab
            ; Do not display weeks 0 and 53 if not used
            If GUICtrlRead($tab) = 0 And Not $fWeek_0 Then _GUICtrlTab_ClickTab($tab, 1)
            If GUICtrlRead($tab) = 53 And Not $fWeek_53 Then _GUICtrlTab_ClickTab($tab, 52)
            $clickedweek = GUICtrlRead($tab)
            GUICtrlSetData($monday, $aWeeks[$clickedweek][1])
            GUICtrlSetData($tuesday, $aWeeks[$clickedweek][2])
            GUICtrlSetData($wednesday, $aWeeks[$clickedweek][3])
            GUICtrlSetData($thursday, $aWeeks[$clickedweek][4])
            GUICtrlSetData($friday, $aWeeks[$clickedweek][5])
            GUICtrlSetData($saturday, $aWeeks[$clickedweek][6])
        Case $hUpDown
            _Calculate()
    EndSwitch

    ; If an item was double clicked
    If $fDblClk Then
        $hListView = $aLV_Handles[$fDblClk]
        $iListView_ID = $fDblClk
        $aHit = _GUICtrlListView_SubItemHitTest($hListView)
        If $aHit[0] <> -1 Then
            _Start_ItemEdit()
        EndIf
        $fDblClk = 0
    EndIf

    If $fEdited Then
        $fEdited = False
        ConsoleWrite("ListView " & $iListView_ID & " : Row " & $aHit[0] + 1 & " : Col " & $aHit[1] + 1 & " has been altered" & @CRLF)

    EndIf

WEnd

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $wParam
    Local $hWndFrom, $iCode, $tNMHDR

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")

    For $i = 1 To 6
        If $aLV_Handles[$i] = $hWndFrom Then
            Switch $iCode
                Case $NM_DBLCLK
                    $fDblClk = $i
            EndSwitch
            ExitLoop
        EndIf
    Next
    Return $GUI_RUNDEFMSG

EndFunc   ;==>WM_NOTIFY

Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)

    #forceref $hWnd, $Msg, $wParam
    Local $iCode = BitShift($wParam, 16)
    Switch $lParam
        Case $hEdit
            Switch $iCode
                Case $EN_KILLFOCUS
                    _End_SubItemEdit()
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

Func _Start_ItemEdit()

    $sItemText = _GUICtrlListView_GetItemText($hListView, $aHit[0], $aHit[1])
    Local $iLen = _GUICtrlListView_GetColumnWidth($hListView, $aHit[1])
    Local $aRect = _GUICtrlListView_GetSubItemRect($hListView, $aHit[0], $aHit[1])
    Local $aPos = WinGetPos($hListView)
    Local $tPoint = DllStructCreate("int X;int Y")
    DllStructSetData($tPoint, "X", $aPos[0])
    DllStructSetData($tPoint, "Y", $aPos[1])
    _WinAPI_ScreenToClient($hGUI, $tPoint)
    Local $iEdit_X = DllStructGetData($tPoint, "X") + $aRect[0]
    Local $iEdit_Y = DllStructGetData($tPoint, "Y") + $aRect[1]
    $hEdit = _GUICtrlEdit_Create($hGUI, $sItemText, $iEdit_X + 6, $iEdit_Y, $iLen - 7, 17, BitOR($WS_CHILD, $WS_VISIBLE, $ES_AUTOHSCROLL, $ES_LEFT))
    _GUICtrlEdit_SetSel($hEdit, 0, -1)
    _WinAPI_SetFocus($hEdit)
    $hDC = _WinAPI_GetWindowDC($hEdit)
    $hBrush = _WinAPI_CreateSolidBrush(0)
    Local $stRect = DllStructCreate("int;int;int;int")
    DllStructSetData($stRect, 1, $iLen + 10)
    DllStructSetData($stRect, 2, 0)
    DllStructSetData($stRect, 3, 0)
    DllStructSetData($stRect, 4, 17)
    DllCall("user32.dll", "int", "FrameRect", "hwnd", $hDC, "ptr", DllStructGetPtr($stRect), "hwnd", $hBrush)
    ; Set acclerator key
    GUISetAccelerators($aAccelKeys)

EndFunc   ;==>_Start_ItemEdit

Func _End_SubItemEdit()

    Local $sText = _GUICtrlEdit_GetText($hEdit)
    If $sText <> $sItemText Then
        _GUICtrlListView_SetItemText($hListView, $aHit[0], $sText, $aHit[1])
        $fEdited = True
    EndIf
    _WinAPI_DeleteObject($hBrush)
    _WinAPI_ReleaseDC($hEdit, $hDC)
    _WinAPI_DestroyWindow($hEdit)
    $hListView = 0
    ; Clear accelerator key
    GUISetAccelerators(0)

EndFunc   ;==>_End_SubItemEdit

Func _Calculate()

    ; Clear array
    Global $aWeeks[54][8]

    ; Set local variables
    Local $asDatePart, $iTimePart
    Local $aDays[8] = [7, "Maandag", "Dinsdag", "Woensdag", "Donderdag", "Vrijdag", "Zaterdag", "Zondag"]
    Local $aMonths[13] = [12, "Januari", "Februari", "Maart", "April", "Mei", "Juni", "Juli", "Augustus", "September", "October", "November", "December"]

    ; Read required year and week
    $sYear = GUICtrlRead($hInput)
    $clickedweek = GUICtrlRead($tab)

    ; Set first day
    $sdate = $sYear & "/01/01"
    ; Set flag to indicate initial week
    $fStart = True
    ; Set flags to indicate 0/53 week empty
    $fWeek_0 = False
    $fWeek_53 = False

    While 1

        ; Split date
        _DateTimeSplit($sdate, $asDatePart, $iTimePart)
        ; Exit if past end required year
        If $asDatePart[1] > $sYear Then ExitLoop

        ; Get week number
        $iWeek = _WeekNumberISO($sYear, $asDatePart[2], $asDatePart[3])

        ; Adjust to cover final part of previous Week 52 if required
        If $fStart Then
            If $iWeek >= 52 Then $iWeek = 0
        Else
            If $iWeek = 1 Then $iWeek = 53
        EndIf
        ; Reset flag if past initial week
        If $iWeek = 2 Then $fStart = False

        ; Get day of week and adjust for Sunday
        $iIndex = _DateToDayOfWeek($sYear, $asDatePart[2], $asDatePart[3])
        If $iIndex = 1 Then
            $iIndex = 8
            ; Adjust for final week if needed
            If Not $fStart And $iWeek = 53 Then $iWeek = 52
        EndIf

        ; Fill array
        $aWeeks[$iWeek][$iIndex - 1] = $aDays[$iIndex - 1] & " " & $asDatePart[3] & " " & $aMonths[$asDatePart[2]]
        ; Move to next day
        $sdate = _DateAdd("d", 1, $sdate)
    WEnd

    ; Check if weeks 0 and 53 are used
    For $i = 1 To 6
        If $aWeeks[0][$i] <> "" Then $fWeek_0 = True
        If $aWeeks[53][$i] <> "" Then $fWeek_53 = True
    Next
    ; If not then do not display them if selected
    If GUICtrlRead($tab) = 0 And Not $fWeek_0 Then _GUICtrlTab_ClickTab($tab, 1)
    If GUICtrlRead($tab) = 53 And Not $fWeek_53 Then _GUICtrlTab_ClickTab($tab, 52)
    $clickedweek = GUICtrlRead($tab)

    GUICtrlSetData($monday, $aWeeks[$clickedweek][1])
    GUICtrlSetData($tuesday, $aWeeks[$clickedweek][2])
    GUICtrlSetData($wednesday, $aWeeks[$clickedweek][3])
    GUICtrlSetData($thursday, $aWeeks[$clickedweek][4])
    GUICtrlSetData($friday, $aWeeks[$clickedweek][5])
    GUICtrlSetData($saturday, $aWeeks[$clickedweek][6])
EndFunc   ;==>_Calculate

I am sure you will be able to follow the new code - but please ask if not. :nuke:

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

yucatan,

Hello again! :D

Another pile of questions - here we go: :x

- 1. The weeks jumped from 1 to 6 because you did this:

for $weeknumber = 1 to 52
    $weeknumber = GUICtrlCreateTabItem("Week "& $weeknumber)
next

After the first tab was created, the value of $weeknumber was set to the value of the ControlID and not the loop variable. The solution is not to store the ControlIDs of the tabs - we can get the index by using GUICtrlRead which is enough for us. :lol:

- 2. You can only edit rows in ListView which actually exist. So we just need to add anough lines to fill the ListView (22 on my machine). I have still entered data so you can see the rows - for the finished article you just leave the items and subitems blank. :P

- 3. I have increased the speed of the script for you. You now only do the full calculation when you change the year - you must do it then to get the array filled! :( But now if all you do is change the week then you just read the existing array to reset the labels.

- 4. The week numbers are now correct. According to ISO, Week 1 is the first full week in the year, so I have added a Week 0 to cater for the times when there are a few days in the final week of the previous year. Similarly, there are times when you get the odd day in Week 53. However, I have arranged things so that the user cannot select these tabs unless there are days to display in those weeks - if the user tries to select Week 0 or 53 and there are no days in that week, the script automatically selects Weeks 1 or 52 instead. The same thing happens if the year is changed and the selected tab is set to one of those weeks which was valid in the previously selected year. :shifty:

Here is the modified script:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <GuiEdit.au3>
#include <Date.au3>
#include <Array.au3>
#include <TabConstants.au3>
#include <EditConstants.au3>
#include <UpdownConstants.au3>
#Include <GuiTab.au3>


Global $fDblClk = 0, $fEdited = False, $fWeek_0 = False, $fWeek_53 = False
Global $hListView = 0, $hEdit, $hDC, $hBrush, $aHit
Global $iListView_ID, $sItemText
Global $aLV_Handles[7]
Global $aWeeks[54][8]
Global $sYear = @YEAR
Global $sdate = $sYear & "/01/01"

Global $hGUI = GUICreate("Test", 900, 940)

$tab = GUICtrlCreateTab(10, 10, 890, 940)
$hTab_0 = GUICtrlCreateTabItem("Week 0")
For $weeknumber = 1 To 53
    GUICtrlCreateTabItem("Week " & $weeknumber)
Next
GUICtrlCreateTabItem("")

GUICtrlSetState(_WeekNumberISO() + $hTab_0, $GUI_SHOW)

$hInput = GUICtrlCreateInput($sYear, 420, 45, 50, 20, $ES_READONLY)
$hUpDown = GUICtrlCreateUpdown($hInput, BitOR($GUI_SS_DEFAULT_UPDOWN, $UDS_WRAP, $UDS_NOTHOUSANDS))
GUICtrlSetLimit($hUpDown, $sYear + 5, $sYear - 5)

$monday = GUICtrlCreateLabel("", 60, 70, 120, 50)
$tuesday = GUICtrlCreateLabel("", 430, 70, 120, 50)
$wednesday = GUICtrlCreateLabel("", 700, 70, 120, 50)
$thursday = GUICtrlCreateLabel("", 100, 500, 130, 50)
$friday = GUICtrlCreateLabel("", 430, 500, 130, 50)
$saturday = GUICtrlCreateLabel("", 700, 500, 130, 50)

_Calculate()

For $i = 1 To 3
    For $j = 0 To 1
        $hListView = _GUICtrlListView_Create($hGUI, "Bus", 15 + (290 * ($i - 1)), 90 + (440 * $j), 299, 406, BitOR($LVS_REPORT, $LVS_SINGLESEL, $WS_BORDER), $LVS_EX_FULLROWSELECT)
        _GUICtrlListView_SetExtendedListViewStyle($hListView, $LVS_EX_FULLROWSELECT)
        $aLV_Handles[$i + ($j * 3)] = $hListView
        _GUICtrlListView_AddColumn($hListView, "Monteur")
        _GUICtrlListView_AddColumn($hListView, "Klant en Project")
        _GUICtrlListView_AddColumn($hListView, "Wvb")
        ControlDisable($hGUI, "", HWnd(_GUICtrlListView_GetHeader($hListView)))
        _GUICtrlListView_SetColumnWidth($hListView, 0, 30)
        _GUICtrlListView_SetColumnWidth($hListView, 1, 60)
        _GUICtrlListView_SetColumnWidth($hListView, 2, 155)
        _GUICtrlListView_SetColumnWidth($hListView, 3, 1)
        ;_GUICtrlListView_SetColumnWidth($hListView, 2, $LVSCW_AUTOSIZE_USEHEADER)
        For $k = 1 To 22
            _GUICtrlListView_AddItem($hListView, "" & $i + ($j * 3) & $k)
            _GUICtrlListView_AddSubItem($hListView, $k - 1, "Sub " & $i + ($j * 3) & Chr(64 + $k), 1)
            _GUICtrlListView_AddSubItem($hListView, $k - 1, "Sub " & $i + ($j * 3) & Chr(77 + $k), 2)
        Next
    Next
Next

; Create dummy control for the accelerator to action
$hAccel_Enter = GUICtrlCreateDummy()
GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

; Set accelerator for Enter to use if editing
Dim $aAccelKeys[1][2] = [["{ENTER}", $hAccel_Enter]]

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $hAccel_Enter
            _End_SubItemEdit()
        Case $tab
            ; Do not display weeks 0 and 53 if not used
            If GUICtrlRead($tab) = 0 And Not $fWeek_0 Then _GUICtrlTab_ClickTab($tab, 1)
            If GUICtrlRead($tab) = 53 And Not $fWeek_53 Then _GUICtrlTab_ClickTab($tab, 52)
            $clickedweek = GUICtrlRead($tab)
            GUICtrlSetData($monday, $aWeeks[$clickedweek][1])
            GUICtrlSetData($tuesday, $aWeeks[$clickedweek][2])
            GUICtrlSetData($wednesday, $aWeeks[$clickedweek][3])
            GUICtrlSetData($thursday, $aWeeks[$clickedweek][4])
            GUICtrlSetData($friday, $aWeeks[$clickedweek][5])
            GUICtrlSetData($saturday, $aWeeks[$clickedweek][6])
        Case $hUpDown
            _Calculate()
    EndSwitch

    ; If an item was double clicked
    If $fDblClk Then
        $hListView = $aLV_Handles[$fDblClk]
        $iListView_ID = $fDblClk
        $aHit = _GUICtrlListView_SubItemHitTest($hListView)
        If $aHit[0] <> -1 Then
            _Start_ItemEdit()
        EndIf
        $fDblClk = 0
    EndIf

    If $fEdited Then
        $fEdited = False
        ConsoleWrite("ListView " & $iListView_ID & " : Row " & $aHit[0] + 1 & " : Col " & $aHit[1] + 1 & " has been altered" & @CRLF)

    EndIf

WEnd

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $wParam
    Local $hWndFrom, $iCode, $tNMHDR

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")

    For $i = 1 To 6
        If $aLV_Handles[$i] = $hWndFrom Then
            Switch $iCode
                Case $NM_DBLCLK
                    $fDblClk = $i
            EndSwitch
            ExitLoop
        EndIf
    Next
    Return $GUI_RUNDEFMSG

EndFunc   ;==>WM_NOTIFY

Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)

    #forceref $hWnd, $Msg, $wParam
    Local $iCode = BitShift($wParam, 16)
    Switch $lParam
        Case $hEdit
            Switch $iCode
                Case $EN_KILLFOCUS
                    _End_SubItemEdit()
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

Func _Start_ItemEdit()

    $sItemText = _GUICtrlListView_GetItemText($hListView, $aHit[0], $aHit[1])
    Local $iLen = _GUICtrlListView_GetColumnWidth($hListView, $aHit[1])
    Local $aRect = _GUICtrlListView_GetSubItemRect($hListView, $aHit[0], $aHit[1])
    Local $aPos = WinGetPos($hListView)
    Local $tPoint = DllStructCreate("int X;int Y")
    DllStructSetData($tPoint, "X", $aPos[0])
    DllStructSetData($tPoint, "Y", $aPos[1])
    _WinAPI_ScreenToClient($hGUI, $tPoint)
    Local $iEdit_X = DllStructGetData($tPoint, "X") + $aRect[0]
    Local $iEdit_Y = DllStructGetData($tPoint, "Y") + $aRect[1]
    $hEdit = _GUICtrlEdit_Create($hGUI, $sItemText, $iEdit_X + 6, $iEdit_Y, $iLen - 7, 17, BitOR($WS_CHILD, $WS_VISIBLE, $ES_AUTOHSCROLL, $ES_LEFT))
    _GUICtrlEdit_SetSel($hEdit, 0, -1)
    _WinAPI_SetFocus($hEdit)
    $hDC = _WinAPI_GetWindowDC($hEdit)
    $hBrush = _WinAPI_CreateSolidBrush(0)
    Local $stRect = DllStructCreate("int;int;int;int")
    DllStructSetData($stRect, 1, $iLen + 10)
    DllStructSetData($stRect, 2, 0)
    DllStructSetData($stRect, 3, 0)
    DllStructSetData($stRect, 4, 17)
    DllCall("user32.dll", "int", "FrameRect", "hwnd", $hDC, "ptr", DllStructGetPtr($stRect), "hwnd", $hBrush)
    ; Set acclerator key
    GUISetAccelerators($aAccelKeys)

EndFunc   ;==>_Start_ItemEdit

Func _End_SubItemEdit()

    Local $sText = _GUICtrlEdit_GetText($hEdit)
    If $sText <> $sItemText Then
        _GUICtrlListView_SetItemText($hListView, $aHit[0], $sText, $aHit[1])
        $fEdited = True
    EndIf
    _WinAPI_DeleteObject($hBrush)
    _WinAPI_ReleaseDC($hEdit, $hDC)
    _WinAPI_DestroyWindow($hEdit)
    $hListView = 0
    ; Clear accelerator key
    GUISetAccelerators(0)

EndFunc   ;==>_End_SubItemEdit

Func _Calculate()

    ; Clear array
    Global $aWeeks[54][8]

    ; Set local variables
    Local $asDatePart, $iTimePart
    Local $aDays[8] = [7, "Maandag", "Dinsdag", "Woensdag", "Donderdag", "Vrijdag", "Zaterdag", "Zondag"]
    Local $aMonths[13] = [12, "Januari", "Februari", "Maart", "April", "Mei", "Juni", "Juli", "Augustus", "September", "October", "November", "December"]

    ; Read required year and week
    $sYear = GUICtrlRead($hInput)
    $clickedweek = GUICtrlRead($tab)

    ; Set first day
    $sdate = $sYear & "/01/01"
    ; Set flag to indicate initial week
    $fStart = True
    ; Set flags to indicate 0/53 week empty
    $fWeek_0 = False
    $fWeek_53 = False

    While 1

        ; Split date
        _DateTimeSplit($sdate, $asDatePart, $iTimePart)
        ; Exit if past end required year
        If $asDatePart[1] > $sYear Then ExitLoop

        ; Get week number
        $iWeek = _WeekNumberISO($sYear, $asDatePart[2], $asDatePart[3])

        ; Adjust to cover final part of previous Week 52 if required
        If $fStart Then
            If $iWeek >= 52 Then $iWeek = 0
        Else
            If $iWeek = 1 Then $iWeek = 53
        EndIf
        ; Reset flag if past initial week
        If $iWeek = 2 Then $fStart = False

        ; Get day of week and adjust for Sunday
        $iIndex = _DateToDayOfWeek($sYear, $asDatePart[2], $asDatePart[3])
        If $iIndex = 1 Then
            $iIndex = 8
            ; Adjust for final week if needed
            If Not $fStart And $iWeek = 53 Then $iWeek = 52
        EndIf

        ; Fill array
        $aWeeks[$iWeek][$iIndex - 1] = $aDays[$iIndex - 1] & " " & $asDatePart[3] & " " & $aMonths[$asDatePart[2]]
        ; Move to next day
        $sdate = _DateAdd("d", 1, $sdate)
    WEnd

    ; Check if weeks 0 and 53 are used
    For $i = 1 To 6
        If $aWeeks[0][$i] <> "" Then $fWeek_0 = True
        If $aWeeks[53][$i] <> "" Then $fWeek_53 = True
    Next
    ; If not then do not display them if selected
    If GUICtrlRead($tab) = 0 And Not $fWeek_0 Then _GUICtrlTab_ClickTab($tab, 1)
    If GUICtrlRead($tab) = 53 And Not $fWeek_53 Then _GUICtrlTab_ClickTab($tab, 52)
    $clickedweek = GUICtrlRead($tab)

    GUICtrlSetData($monday, $aWeeks[$clickedweek][1])
    GUICtrlSetData($tuesday, $aWeeks[$clickedweek][2])
    GUICtrlSetData($wednesday, $aWeeks[$clickedweek][3])
    GUICtrlSetData($thursday, $aWeeks[$clickedweek][4])
    GUICtrlSetData($friday, $aWeeks[$clickedweek][5])
    GUICtrlSetData($saturday, $aWeeks[$clickedweek][6])
EndFunc   ;==>_Calculate

I am sure you will be able to follow the new code - but please ask if not. :nuke:

M23

Hello M23

thanks alot for ur help!!!!

still i have one qestion.

in this topic they talk about search in a large listview.

i was wandering.

i wanne search in a listview i wanne have a filter field for earch collum and on the fly search so when i try in the field is already start with searching and rebuilding the listview.

if i make the search fields emty that it restores the orginal list.

if i enter bus 44 and wvb HT

they it shows all the record of the listview where bus = 44 and where wvb = HT

and ofcourse a reset button.

how this can be done?

this is the code i already have:

#include <GuiConstantsEx.au3>
#include <GuiListView.au3>

Global $aLVItems[4][2]

$aLVItems[0][0] = 3

$aLVItems[1][1] = "Notepad|For text writing"
$aLVItems[2][1] = "WordPad|For text writing (advanced)"
$aLVItems[3][1] = "Paint|Image making"

$hGUI = GUICreate("Test", 330, 200)

$cListView = GUICtrlCreateListView("Program|Description", 10, 10, 310, 140)

For $i = 1 To $aLVItems[0][0]
    $aLVItems[$i][0] = GUICtrlCreateListViewItem($aLVItems[$i][1], $cListView)
Next

$cInput_Filter = GUICtrlCreateInput("", 11, 167, 140, 20)

$cButton_Filter = GUICtrlCreateButton("Filter", 160, 166, 75, 23)

$cButton_All = GUICtrlCreateButton("All", 246, 166, 75, 23)

GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cButton_Filter
            _FilterItem(GUICtrlRead($cInput_Filter))
        Case $cButton_All
            _ShowAll()
    EndSwitch
WEnd

Func _FilterItem($sText)
    If ($sText = "") Then Return
    Local $strNew = ''
    For $i = 1 To $aLVItems[0][0]
        If StringInStr(_GUICtrlListView_GetItemText($cListView, $i-1), $sText) Then $strNew &= '$aLVItems['&$i&'][0] = GUICtrlCreateListViewItem($aLVItems['&$i&'][1], $cListView)' & @LF
    Next
    If $strNew = '' Then Return
    _GUICtrlListView_DeleteAllItems($cListView)
    Local $aExecute = StringSplit($strNew, @LF)
    For $i = 1 To UBound($aExecute) -1
        Execute($aExecute[$i])
    Next
EndFunc   ;==>_FilterItem

Func _ShowAll()
    If GUICtrlSendMsg($cListView, $LVM_GETITEMCOUNT, 0, 0) = $aLVItems[0][0] Then Return
    
    Local $i
    
    GUICtrlSendMsg($cListView, $LVM_DELETEALLITEMS, 0, 0)
    
    For $i = 1 To $aLVItems[0][0]
        $aLVItems[$i][0] = GUICtrlCreateListViewItem($aLVItems[$i][1], $cListView)
    Next
EndFunc   ;==>_ShowAll

so that when i search for writing.

that i get 2 results

Is it possible to create a raster in my listview

so horizantal and vertical lines in my listview.

is it possible to create a dropdown box in my listview?

so that in a field a user can only select what the drop box shows?

Maby u can test the code urself because the clicking does not work very smooth.

when i fill in a bus number and i try to fill in the other fields that does not work great.

Thanks alot Greetz!

Edited by yucatan
Link to comment
Share on other sites

  • Moderators

yucatan,

- 1. Searching ListViews. Time for you to do some work - almost every line in that script is from me so far. :x You have a go at scripting something first before I end up doing all the work again.

- 2. "horizantal and vertical lines in my listview". Do this:

_GUICtrlListView_SetExtendedListViewStyle($hListView, $LVS_EX_GRIDLINES) ; Set grid lines

But you may need to change the background colour of the ListView before you see the lines - on my monitor the lines are almost the same colour as the normal ListView colour. :lol:

- 3. "is it possible to create a dropdown box in my listview?". Yes and you can do it like this: :P

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <Date.au3>
#include <Array.au3>
#include <TabConstants.au3>
#include <EditConstants.au3>
#include <UpdownConstants.au3>
#Include <GuiTab.au3>

#Include <GuiComboBox.au3>
#include <Misc.au3>

Global $fDblClk = 0, $fWeek_0 = False, $fWeek_53 = False
Global $hListView = 0, $hEdit_Combo = 0, $aLV_Click_Info
Global $iListView_ID, $sItemText
Global $aLV_Handles[7], $aDayLabels[7]
Global $aWeeks[54][8]
Global $sYear = @YEAR
Global $sdate = $sYear & "/01/01"

; Open DLL for _IsPressed
Global $dll = DllOpen("user32.dll")

Global $hGUI = GUICreate("Test", 900, 940)

$hTab = GUICtrlCreateTab(10, 10, 890, 940)
$hTab_0 = GUICtrlCreateTabItem("Week 0")
For $i = 1 To 53
    GUICtrlCreateTabItem("Week " & $i)
Next
GUICtrlCreateTabItem("")

GUICtrlSetState(_WeekNumberISO() + $hTab_0, $GUI_SHOW)

$hInput = GUICtrlCreateInput($sYear, 420, 45, 50, 20, $ES_READONLY)
$hUpDown = GUICtrlCreateUpdown($hInput, BitOR($GUI_SS_DEFAULT_UPDOWN, $UDS_WRAP, $UDS_NOTHOUSANDS))
GUICtrlSetLimit($hUpDown, $sYear + 5, $sYear - 5)

For $i = 1 To 3
    For $j = 0 To 1

        $iX = 15 + (290 * ($i - 1))
        $iY = 90 + (440 * $j)

        $aDayLabels[(3 * $j) + $i] = GUICtrlCreateLabel("", $iX + 40, $iY - 20, 150, 25)

        $hListView = _GUICtrlListView_Create($hGUI, "Bus", $iX, $iY, 299, 406, BitOR($LVS_REPORT, $LVS_SINGLESEL, $WS_BORDER), $LVS_EX_FULLROWSELECT)
        _GUICtrlListView_SetExtendedListViewStyle($hListView, $LVS_EX_FULLROWSELECT)
        $aLV_Handles[$i + ($j * 3)] = $hListView
        _GUICtrlListView_AddColumn($hListView, "Monteur")
        _GUICtrlListView_AddColumn($hListView, "Klant en Project")
        _GUICtrlListView_AddColumn($hListView, "Wvb")
        ControlDisable($hGUI, "", HWnd(_GUICtrlListView_GetHeader($hListView)))
        _GUICtrlListView_SetColumnWidth($hListView, 0, 30)
        _GUICtrlListView_SetColumnWidth($hListView, 1, 60)
        _GUICtrlListView_SetColumnWidth($hListView, 2, 155)
        _GUICtrlListView_SetColumnWidth($hListView, 3, $LVSCW_AUTOSIZE_USEHEADER)
        For $k = 1 To 22
            _GUICtrlListView_AddItem($hListView, "" & $i + ($j * 3) & $k)
            _GUICtrlListView_AddSubItem($hListView, $k - 1, "Sub " & $i + ($j * 3) & Chr(64 + $k), 1)
            _GUICtrlListView_AddSubItem($hListView, $k - 1, "Sub " & $i + ($j * 3) & Chr(77 + $k), 2)
        Next
    Next
Next

_Calculate()

GUISetState()

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            DllClose($dll)
            Exit
        Case $hTab
            ; Do not display weeks 0 and 53 if not used
            If GUICtrlRead($hTab) = 0 And Not $fWeek_0 Then _GUICtrlTab_ClickTab($hTab, 1)
            If GUICtrlRead($hTab) = 53 And Not $fWeek_53 Then _GUICtrlTab_ClickTab($hTab, 52)
            $clickedweek = GUICtrlRead($hTab)
            For $i = 1 To 6
                GUICtrlSetData($aDayLabels[$i], $aWeeks[$clickedweek][1])
            Next
        Case $hUpDown
            _Calculate()
    EndSwitch

    ; If an item was double clicked
    If $fDblClk Then
        ; Get ListView details
        $hListView = $aLV_Handles[$fDblClk]
        $iListView_ID = $fDblClk
        ; Reset flag
        $fDblClk = 0
        ; Get details item clicked
        $aLV_Click_Info = _GUICtrlListView_SubItemHitTest($hListView)
        If $aLV_Click_Info[0] <> -1 Then

            ; Delete any existing combo
            GUICtrlDelete($hEdit_Combo)
            ; Get current text
            $sItemText = _GUICtrlListView_GetItemText($hListView, $aLV_Click_Info[0], $aLV_Click_Info[1])
            ; Get position
            Local $aRect = _GUICtrlListView_GetSubItemRect($hListView, $aLV_Click_Info[0], $aLV_Click_Info[1])
            Local $aPos = WinGetPos($hListView)
            Local $tPoint = DllStructCreate("int X;int Y")
            DllStructSetData($tPoint, "X", $aPos[0])
            DllStructSetData($tPoint, "Y", $aPos[1])
            _WinAPI_ScreenToClient($hGUI, $tPoint)
            Local $iEdit_X = DllStructGetData($tPoint, "X") + $aRect[0]
            Local $iEdit_Y = DllStructGetData($tPoint, "Y") + $aRect[1]

            ; Create edit combo
            $hEdit_Combo = GUICtrlCreateCombo("",  $iEdit_X,  $iEdit_Y, 100, 20)
            ; Set combo values depending on column clicked
            Switch $aLV_Click_Info[1]
                Case 0
                    GUICtrlSetData($hEdit_Combo, "Bus 1|Bus 2|Bus 3")
                Case 1
                    GUICtrlSetData($hEdit_Combo, "Monteur 1|Monteur 2|Monteur 3")
                Case 2
                    GUICtrlSetData($hEdit_Combo, "Klant 1|Klant 2|Klant 3")
                Case 3
                    GUICtrlSetData($hEdit_Combo, "Wvb 1|Wvb 2|Wvb 3")
            EndSwitch
            GUICtrlSetState($hEdit_Combo, BitOR($GUI_FOCUS, $GUI_ONTOP))

            ; Get handle of combo edit control
            $hComboEdit = _WinAPI_GetFocus()
            ; Set flag for Enter pressed
            $iLoopCode = 0

            ; Loop while the combo has focus
            While _WinAPI_GetFocus() = $hComboEdit
                ; If ENTER pressed
                If _IsPressed("0D", $dll) Then
                    $iLoopCode = 1
                    ExitLoop
                EndIf
                ; If ESC pressed
                If _IsPressed("1B", $dll) Then ExitLoop
                ; Save CPU
                Sleep(10)
            WEnd
            ; Edit ListView if Enter pressed
            If $iLoopCode Then
                ; Set label to edit content
                $sText = GUICtrlRead($hEdit_Combo)
                _GUICtrlListView_SetItemText($hListView, $aLV_Click_Info[0], $sText, $aLV_Click_Info[1])
            EndIf
            ; Delete combo
            GUICtrlDelete($hEdit_Combo)
            $hEdit_Combo = 0
        EndIf

    EndIf

WEnd

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $wParam
    Local $hWndFrom, $iCode, $tNMHDR

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")

    For $i = 1 To 6
        If $aLV_Handles[$i] = $hWndFrom Then
            Switch $iCode
                Case $NM_DBLCLK
                    $fDblClk = $i
            EndSwitch
            ExitLoop
        EndIf
    Next
    Return $GUI_RUNDEFMSG

EndFunc   ;==>WM_NOTIFY

Func _Calculate()

    ; Clear array
    Global $aWeeks[54][8]

    ; Set local variables
    Local $asDatePart, $iTimePart
    Local $aDays[8] = [7, "Maandag", "Dinsdag", "Woensdag", "Donderdag", "Vrijdag", "Zaterdag", "Zondag"]
    Local $aMonths[13] = [12, "Januari", "Februari", "Maart", "April", "Mei", "Juni", "Juli", "Augustus", "September", "October", "November", "December"]

    ; Read required year and week
    $sYear = GUICtrlRead($hInput)
    $clickedweek = GUICtrlRead($hTab)

    ; Set first day
    $sdate = $sYear & "/01/01"
    ; Set flag to indicate initial week
    $fStart = True
    ; Set flags to indicate 0/53 week empty
    $fWeek_0 = False
    $fWeek_53 = False

    While 1

        ; Split date
        _DateTimeSplit($sdate, $asDatePart, $iTimePart)
        ; Exit if past end required year
        If $asDatePart[1] > $sYear Then ExitLoop

        ; Get week number
        $iWeek = _WeekNumberISO($sYear, $asDatePart[2], $asDatePart[3])

        ; Adjust to cover final part of previous Week 52 if required
        If $fStart Then
            If $iWeek >= 52 Then $iWeek = 0
        Else
            If $iWeek = 1 Then $iWeek = 53
        EndIf
        ; Reset flag if past initial week
        If $iWeek = 2 Then $fStart = False

        ; Get day of week and adjust for Sunday
        $iIndex = _DateToDayOfWeek($sYear, $asDatePart[2], $asDatePart[3])
        If $iIndex = 1 Then
            $iIndex = 8
            ; Adjust for final week if needed
            If Not $fStart And $iWeek = 53 Then $iWeek = 52
        EndIf

        ; Fill array
        $aWeeks[$iWeek][$iIndex - 1] = $aDays[$iIndex - 1] & " " & $asDatePart[3] & " " & $aMonths[$asDatePart[2]]
        ; Move to next day
        $sdate = _DateAdd("d", 1, $sdate)
    WEnd

    ; Check if weeks 0 and 53 are used
    For $i = 1 To 6
        If $aWeeks[0][$i] <> "" Then $fWeek_0 = True
        If $aWeeks[53][$i] <> "" Then $fWeek_53 = True
    Next
    ; If not then do not display them if selected
    If GUICtrlRead($hTab) = 0 And Not $fWeek_0 Then _GUICtrlTab_ClickTab($hTab, 1)
    If GUICtrlRead($hTab) = 53 And Not $fWeek_53 Then _GUICtrlTab_ClickTab($hTab, 52)
    $clickedweek = GUICtrlRead($hTab)

    For $i = 1 To 6
        ConsoleWrite($aDayLabels[$i] & " - " & $aWeeks[$clickedweek][$i] & @CRLF)
        GUICtrlSetData($aDayLabels[$i], $aWeeks[$clickedweek][$i])
    Next

EndFunc   ;==>_Calculate

You must use "Enter" to confirm an edit - "Escape" or clicking other than in the combo abandons the edit.

A couple of other things:

- a. I have changed the code for the editing - it is now much simpler.

- b. You can set different values in the combo depending on the column you have clicked.

- c. I have tidied the code significantly.

- 4. "Maby u can test the code urself because the clicking does not work very smooth". A touch ungrateful, in my opinion! :nuke: I mentioned above that I had changed the code - try it now and see if it works better for you. :(

; ----------

OK - no more help from me until you have done some work. Try and get the ListView search working and show me some code that you have produced and which is not just lifted from another post. :D

M23

P.S. And please remember to use the "Add Reply" button at the top and bottom of the page rather then the "Reply" button in the post itself. That way you do not get the contents of the previous post quoted in your reply and the whole thread becomes easier to read. :shifty:

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

Hello M23.

I'm back again.

here is some code

i have a couple of problems.

i have changed dubble click to single click.

at this point when i change the week. all the days are the same day and date.

so there is something wrong is the change week proces.

when i modify the year then everything is fine again when i change week again it goes wrong.

i would like that if i have a combo box.

and i click the down arrow.

and i click a rule so that i select a word.

i want it to be filled in in the listview.

as u see i already build that but it dont work fully.

my english is not that good i can explane what goes wrong but if u test u will notice.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <Date.au3>
#include <Array.au3>
#include <TabConstants.au3>
#include <EditConstants.au3>
#include <UpdownConstants.au3>
#Include <GuiTab.au3>

#Include <GuiComboBox.au3>
#include <Misc.au3>

Global $fDblClk = 0, $fWeek_0 = False, $fWeek_53 = False
Global $hListView = 0, $hEdit_Combo = 0, $aLV_Click_Info
Global $iListView_ID, $sItemText
Global $aLV_Handles[7], $aDayLabels[7]
Global $aWeeks[54][8]
Global $sYear = @YEAR
Global $sdate = $sYear & "/01/01"
global $buswidth = 30
global $monteurwidth = 60
global $klantwidth = 155
; Open DLL for _IsPressed
Global $dll = DllOpen("user32.dll")

Global $hGUI = GUICreate("Test", 900, 940)

$hTab = GUICtrlCreateTab(10, 10, 890, 940)
$hTab_0 = GUICtrlCreateTabItem("Week 0")
For $i = 1 To 53
    GUICtrlCreateTabItem("Week " & $i)
Next
GUICtrlCreateTabItem("")

GUICtrlSetState(_WeekNumberISO() + $hTab_0, $GUI_SHOW)


$hInput = GUICtrlCreateInput($sYear, 420, 45, 50, 20, $ES_READONLY)
$hUpDown = GUICtrlCreateUpdown($hInput, BitOR($GUI_SS_DEFAULT_UPDOWN, $UDS_WRAP, $UDS_NOTHOUSANDS))
GUICtrlSetLimit($hUpDown, $sYear + 5, $sYear - 5)

For $i = 1 To 3
    For $j = 0 To 1

        $iX = 15 + (290 * ($i - 1))
        $iY = 90 + (440 * $j)

        $aDayLabels[(3 * $j) + $i] = GUICtrlCreateLabel("", $iX + 40, $iY - 20, 150, 25)

        $hListView = _GUICtrlListView_Create($hGUI, "Bus", $iX, $iY, 285, 407, BitOR($LVS_REPORT, $LVS_SINGLESEL, $WS_BORDER), $LVS_EX_FULLROWSELECT)
        _GUICtrlListView_SetExtendedListViewStyle($hListView,$LVS_EX_GRIDLINES)

        $aLV_Handles[$i + ($j * 3)] = $hListView
        _GUICtrlListView_AddColumn($hListView, "Monteur")
        _GUICtrlListView_AddColumn($hListView, "Klant en Project")
        _GUICtrlListView_AddColumn($hListView, "Wvb")
        ControlDisable($hGUI, "", HWnd(_GUICtrlListView_GetHeader($hListView)))
        _GUICtrlListView_SetColumnWidth($hListView, 0, $buswidth)
        _GUICtrlListView_SetColumnWidth($hListView, 1, $monteurwidth)
        _GUICtrlListView_SetColumnWidth($hListView, 2, $klantwidth)
        _GUICtrlListView_SetColumnWidth($hListView, 3, $LVSCW_AUTOSIZE_USEHEADER)
        For $k = 1 To 22
            _GUICtrlListView_AddItem($hListView, "" & $i + ($j * 3) & $k)
            _GUICtrlListView_AddSubItem($hListView, $k - 1, "Sub " & $i + ($j * 3) & Chr(64 + $k), 1)
            _GUICtrlListView_AddSubItem($hListView, $k - 1, "Sub " & $i + ($j * 3) & Chr(77 + $k), 2)
        Next
    Next
Next

_Calculate()

GUISetState()

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            DllClose($dll)
            Exit
        Case $hTab
            ; Do not display weeks 0 and 53 if not used
            If GUICtrlRead($hTab) = 0 And Not $fWeek_0 Then _GUICtrlTab_ClickTab($hTab, 1)
            If GUICtrlRead($hTab) = 53 And Not $fWeek_53 Then _GUICtrlTab_ClickTab($hTab, 52)
            $clickedweek = GUICtrlRead($hTab)
            For $i = 1 To 6
                GUICtrlSetData($aDayLabels[$i], $aWeeks[$clickedweek][1])
            Next
        Case $hUpDown
            _Calculate()
    EndSwitch

    ; If an item was clicked
    If $fDblClk Then
        ; Get ListView details
        $hListView = $aLV_Handles[$fDblClk]
        $iListView_ID = $fDblClk
        ; Reset flag
        $fDblClk = 0
        ; Get details item clicked
        $aLV_Click_Info = _GUICtrlListView_SubItemHitTest($hListView)
        If $aLV_Click_Info[0] <> -1 Then

            ; Delete any existing combo
            GUICtrlDelete($hEdit_Combo)
            ; Get current text
            $sItemText = _GUICtrlListView_GetItemText($hListView, $aLV_Click_Info[0], $aLV_Click_Info[1])
            ; Get position
            Local $aRect = _GUICtrlListView_GetSubItemRect($hListView, $aLV_Click_Info[0], $aLV_Click_Info[1])
            Local $aPos = WinGetPos($hListView)
            Local $tPoint = DllStructCreate("int X;int Y")
            DllStructSetData($tPoint, "X", $aPos[0])
            DllStructSetData($tPoint, "Y", $aPos[1])
            _WinAPI_ScreenToClient($hGUI, $tPoint)
            Local $iEdit_X = DllStructGetData($tPoint, "X") + $aRect[0]
            Local $iEdit_Y = DllStructGetData($tPoint, "Y") + $aRect[1]

            ; Create edit combo
            $hEdit_Combo = GUICtrlCreateCombo("",  $iEdit_X,  $iEdit_Y, 50, 20)
            ; Set combo values depending on column clicked
            Switch $aLV_Click_Info[1]
                Case 0
                    GUICtrlSetData($hEdit_Combo, "Bus 1|Bus 2|Bus 3")
                    GUICtrlSetPos($hEdit_Combo, $iEdit_X,  $iEdit_Y, $buswidth, 20)
                Case 1
                    GUICtrlSetData($hEdit_Combo, "Monteur 1|Monteur 2|Monteur 3")
                    GUICtrlSetPos($hEdit_Combo, $iEdit_X,  $iEdit_Y, $monteurwidth , 20)
                Case 2
                    GUICtrlSetData($hEdit_Combo, "Klant 1|Klant 2|Klant 3")
                    GUICtrlSetPos($hEdit_Combo, $iEdit_X,  $iEdit_Y, $klantwidth, 20)
                Case 3
                    GUICtrlSetData($hEdit_Combo, "Wvb 1|Wvb 2|Wvb 3")
                    GUICtrlSetPos($hEdit_Combo, $iEdit_X,$iEdit_Y, 40, 20)
            EndSwitch
            GUICtrlSetState($hEdit_Combo, BitOR($GUI_FOCUS, $GUI_ONTOP))

            ; Get handle of combo edit control
            $hComboEdit = _WinAPI_GetFocus()
            ; Set flag for Enter pressed
            $iLoopCode = 0

            ; Loop while the combo has focus
            While _WinAPI_GetFocus() = $hComboEdit
                if GUICtrlRead($hEdit_Combo) <> "" then
                $iLoopCode = 1
                ExitLoop
                EndIf


                ; If ENTER pressed
                If _IsPressed("0D", $dll) Then
                    $iLoopCode = 1
                    ExitLoop
                EndIf
                ; If ESC pressed
                If _IsPressed("1B", $dll) Then ExitLoop
                ; Save CPU
                Sleep(10)
            WEnd
            ; Edit ListView if Enter pressed
            If $iLoopCode Then
                ; Set label to edit content
                $sText = GUICtrlRead($hEdit_Combo)
                _GUICtrlListView_SetItemText($hListView, $aLV_Click_Info[0], $sText, $aLV_Click_Info[1])
            EndIf
            ; Delete combo
            GUICtrlDelete($hEdit_Combo)
            $hEdit_Combo = 0
        EndIf

    EndIf

WEnd

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $wParam
    Local $hWndFrom, $iCode, $tNMHDR

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")

    For $i = 1 To 6
        If $aLV_Handles[$i] = $hWndFrom Then
            Switch $iCode
                Case $NM_CLICK
                    $fDblClk = $i
            EndSwitch
            ExitLoop
        EndIf
    Next
    Return $GUI_RUNDEFMSG

EndFunc   ;==>WM_NOTIFY

Func _Calculate()

    ; Clear array
    Global $aWeeks[54][8]

    ; Set local variables
    Local $asDatePart, $iTimePart
    Local $aDays[8] = [7, "Maandag", "Dinsdag", "Woensdag", "Donderdag", "Vrijdag", "Zaterdag", "Zondag"]
    Local $aMonths[13] = [12, "Januari", "Februari", "Maart", "April", "Mei", "Juni", "Juli", "Augustus", "September", "October", "November", "December"]

    ; Read required year and week
    $sYear = GUICtrlRead($hInput)
    $clickedweek = GUICtrlRead($hTab)

    ; Set first day
    $sdate = $sYear & "/01/01"
    ; Set flag to indicate initial week
    $fStart = True
    ; Set flags to indicate 0/53 week empty
    $fWeek_0 = False
    $fWeek_53 = False

    While 1

        ; Split date
        _DateTimeSplit($sdate, $asDatePart, $iTimePart)
        ; Exit if past end required year
        If $asDatePart[1] > $sYear Then ExitLoop

        ; Get week number
        $iWeek = _WeekNumberISO($sYear, $asDatePart[2], $asDatePart[3])

        ; Adjust to cover final part of previous Week 52 if required
        If $fStart Then
            If $iWeek >= 52 Then $iWeek = 0
        Else
            If $iWeek = 1 Then $iWeek = 53
        EndIf
        ; Reset flag if past initial week
        If $iWeek = 2 Then $fStart = False

        ; Get day of week and adjust for Sunday
        $iIndex = _DateToDayOfWeek($sYear, $asDatePart[2], $asDatePart[3])
        If $iIndex = 1 Then
            $iIndex = 8
            ; Adjust for final week if needed
            If Not $fStart And $iWeek = 53 Then $iWeek = 52
        EndIf

        ; Fill array
        $aWeeks[$iWeek][$iIndex - 1] = $aDays[$iIndex - 1] & " " & $asDatePart[3] & " " & $aMonths[$asDatePart[2]]
        ; Move to next day
        $sdate = _DateAdd("d", 1, $sdate)
    WEnd

    ; Check if weeks 0 and 53 are used
    For $i = 1 To 6
        If $aWeeks[0][$i] <> "" Then $fWeek_0 = True
        If $aWeeks[53][$i] <> "" Then $fWeek_53 = True
    Next
    ; If not then do not display them if selected
    If GUICtrlRead($hTab) = 0 And Not $fWeek_0 Then _GUICtrlTab_ClickTab($hTab, 1)
    If GUICtrlRead($hTab) = 53 And Not $fWeek_53 Then _GUICtrlTab_ClickTab($hTab, 52)
    $clickedweek = GUICtrlRead($hTab)

    For $i = 1 To 6
        ConsoleWrite($aDayLabels[$i] & " - " & $aWeeks[$clickedweek][$i] & @CRLF)
        GUICtrlSetData($aDayLabels[$i], $aWeeks[$clickedweek][$i])
    Next

EndFunc   ;==>_Calculate
Link to comment
Share on other sites

  • Moderators

yucatan,

i have changed dubble click to single click.

Good. :P

when i change the week. all the days are the same day and date

Sorry - typo on my part. :x It now works correctly.

i select a word. i want it to be filled in in the listview

Done - look for the <<<<<<<<<<<<<< lines. It replaces the "Enter" code, which is no longer necessary. See how you have to check if the Combo is closed as well as if there is something in the Combo edit control. If you do not do this, then the code will fire as you scroll over the items in the combo rather than when you select one. :shifty:

Her is the new version:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <Date.au3>
#include <Array.au3>
#include <TabConstants.au3>
#include <EditConstants.au3>
#include <UpdownConstants.au3>
#Include <GuiTab.au3>

#Include <GuiComboBox.au3>
#include <Misc.au3>

Opt("GUICloseOnESC", 0)

Global $fClicked = 0, $fWeek_0 = False, $fWeek_53 = False
Global $hListView = 0, $hEdit_Combo = 0, $aLV_Click_Info
Global $iListView_ID, $sItemText
Global $aLV_Handles[7], $aDayLabels[7]
Global $aWeeks[54][8]
Global $sYear = @YEAR
Global $sdate = $sYear & "/01/01"
Global $buswidth = 30, $monteurwidth = 60, $klantwidth = 155

; Open DLL for _IsPressed
Global $dll = DllOpen("user32.dll")

Global $hGUI = GUICreate("Test", 900, 940)

$hTab = GUICtrlCreateTab(10, 10, 890, 940)
$hTab_0 = GUICtrlCreateTabItem("Week 0")
For $i = 1 To 53
    GUICtrlCreateTabItem("Week " & $i)
Next
GUICtrlCreateTabItem("")

GUICtrlSetState(_WeekNumberISO() + $hTab_0, $GUI_SHOW)

$hInput = GUICtrlCreateInput($sYear, 420, 45, 50, 20, $ES_READONLY)
$hUpDown = GUICtrlCreateUpdown($hInput, BitOR($GUI_SS_DEFAULT_UPDOWN, $UDS_WRAP, $UDS_NOTHOUSANDS))
GUICtrlSetLimit($hUpDown, $sYear + 5, $sYear - 5)

For $i = 1 To 3
    For $j = 0 To 1

        $iX = 15 + (290 * ($i - 1))
        $iY = 90 + (440 * $j)

        $aDayLabels[(3 * $j) + $i] = GUICtrlCreateLabel("", $iX + 40, $iY - 20, 150, 25)

        $hListView = _GUICtrlListView_Create($hGUI, "Bus", $iX, $iY, 285, 407, BitOR($LVS_REPORT, $LVS_SINGLESEL, $WS_BORDER), $LVS_EX_FULLROWSELECT)
        _GUICtrlListView_SetExtendedListViewStyle($hListView, $LVS_EX_FULLROWSELECT)
        $aLV_Handles[$i + ($j * 3)] = $hListView
        _GUICtrlListView_AddColumn($hListView, "Monteur")
        _GUICtrlListView_AddColumn($hListView, "Klant en Project")
        _GUICtrlListView_AddColumn($hListView, "Wvb")
        ControlDisable($hGUI, "", HWnd(_GUICtrlListView_GetHeader($hListView)))
        _GUICtrlListView_SetColumnWidth($hListView, 0, $buswidth)
        _GUICtrlListView_SetColumnWidth($hListView, 1, $monteurwidth)
        _GUICtrlListView_SetColumnWidth($hListView, 2, $klantwidth)
        _GUICtrlListView_SetColumnWidth($hListView, 3, $LVSCW_AUTOSIZE_USEHEADER)
        For $k = 1 To 22
            _GUICtrlListView_AddItem($hListView, "" & $i + ($j * 3) & $k)
            _GUICtrlListView_AddSubItem($hListView, $k - 1, "Sub " & $i + ($j * 3) & Chr(64 + $k), 1)
            _GUICtrlListView_AddSubItem($hListView, $k - 1, "Sub " & $i + ($j * 3) & Chr(77 + $k), 2)
        Next
    Next
Next

_Calculate()

GUISetState()

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            DllClose($dll)
            Exit
        Case $hTab
            ; Do not display weeks 0 and 53 if not used
            If GUICtrlRead($hTab) = 0 And Not $fWeek_0 Then _GUICtrlTab_ClickTab($hTab, 1)
            If GUICtrlRead($hTab) = 53 And Not $fWeek_53 Then _GUICtrlTab_ClickTab($hTab, 52)
            $clickedweek = GUICtrlRead($hTab)
            For $i = 1 To 6
                GUICtrlSetData($aDayLabels[$i], $aWeeks[$clickedweek][$i])
            Next
        Case $hUpDown
            _Calculate()
    EndSwitch

    ; If an item was double clicked
    If $fClicked Then
        ; Get ListView details
        $hListView = $aLV_Handles[$fClicked]
        $iListView_ID = $fClicked
        ; Reset flag
        $fClicked = 0
        ; Get details item clicked
        $aLV_Click_Info = _GUICtrlListView_SubItemHitTest($hListView)
        If $aLV_Click_Info[0] <> -1 Then

            ; Delete any existing combo
            GUICtrlDelete($hEdit_Combo)
            ; Get current text
            $sItemText = _GUICtrlListView_GetItemText($hListView, $aLV_Click_Info[0], $aLV_Click_Info[1])
            ; Get position
            Local $aRect = _GUICtrlListView_GetSubItemRect($hListView, $aLV_Click_Info[0], $aLV_Click_Info[1])
            Local $aPos = WinGetPos($hListView)
            Local $tPoint = DllStructCreate("int X;int Y")
            DllStructSetData($tPoint, "X", $aPos[0])
            DllStructSetData($tPoint, "Y", $aPos[1])
            _WinAPI_ScreenToClient($hGUI, $tPoint)
            Local $iEdit_X = DllStructGetData($tPoint, "X") + $aRect[0]
            Local $iEdit_Y = DllStructGetData($tPoint, "Y") + $aRect[1]

            ; Get column width
            Local $iWidth = _GUICtrlListView_GetColumnWidth($hListView, $aLV_Click_Info[1])
            ; Create edit combo
            $hEdit_Combo = GUICtrlCreateCombo("",  $iEdit_X,  $iEdit_Y, $iWidth, 20)
            ; Set combo values depending on column clicked
            Switch $aLV_Click_Info[1]
                Case 0
                    GUICtrlSetData($hEdit_Combo, "1 Bus|2 Bus|3 Bus")
                Case 1
                    GUICtrlSetData($hEdit_Combo, "Monteur 1|Monteur 2|Monteur 3")
                Case 2
                    GUICtrlSetData($hEdit_Combo, "Klant 1|Klant 2|Klant 3")
                Case 3
                    GUICtrlSetData($hEdit_Combo, "Wvb 1|Wvb 2|Wvb 3")
            EndSwitch
            GUICtrlSetState($hEdit_Combo, BitOR($GUI_FOCUS, $GUI_ONTOP))

            ; Get handle of combo edit control
            $hComboEdit = _WinAPI_GetFocus()
            ; Set flag for Enter pressed
            $iLoopCode = 0

            ; Loop while the combo has focus
            While _WinAPI_GetFocus() = $hComboEdit

                ; If combo is filled <<<<<<<<<<<<<<
                If GUICtrlRead($hEdit_Combo) <> "" And _GUICtrlComboBox_GetDroppedState($hEdit_Combo) = False Then ; <<<<<<<<<<<<<<
                    $iLoopCode = 1
                    ExitLoop
                EndIf
                ; If ESC pressed
                If _IsPressed("1B", $dll) Then ExitLoop
                ; Save CPU
                Sleep(10)
            WEnd
            ; Edit ListView if Enter pressed
            If $iLoopCode Then
                ; Set label to edit content
                $sText = GUICtrlRead($hEdit_Combo)
                _GUICtrlListView_SetItemText($hListView, $aLV_Click_Info[0], $sText, $aLV_Click_Info[1])
            EndIf
            ; Delete combo
            GUICtrlDelete($hEdit_Combo)
            $hEdit_Combo = 0
        EndIf

    EndIf

WEnd

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $wParam
    Local $hWndFrom, $iCode, $tNMHDR

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")

    For $i = 1 To 6
        If $aLV_Handles[$i] = $hWndFrom Then
            Switch $iCode
                Case $NM_CLICK
                    $fClicked = $i
            EndSwitch
            ExitLoop
        EndIf
    Next
    Return $GUI_RUNDEFMSG

EndFunc   ;==>WM_NOTIFY

Func _Calculate()

    ; Clear array
    Global $aWeeks[54][8]

    ; Set local variables
    Local $asDatePart, $iTimePart
    Local $aDays[8] = [7, "Maandag", "Dinsdag", "Woensdag", "Donderdag", "Vrijdag", "Zaterdag", "Zondag"]
    Local $aMonths[13] = [12, "Januari", "Februari", "Maart", "April", "Mei", "Juni", "Juli", "Augustus", "September", "October", "November", "December"]

    ; Read required year and week
    $sYear = GUICtrlRead($hInput)
    $clickedweek = GUICtrlRead($hTab)

    ; Set first day
    $sdate = $sYear & "/01/01"
    ; Set flag to indicate initial week
    $fStart = True
    ; Set flags to indicate 0/53 week empty
    $fWeek_0 = False
    $fWeek_53 = False

    While 1

        ; Split date
        _DateTimeSplit($sdate, $asDatePart, $iTimePart)
        ; Exit if past end required year
        If $asDatePart[1] > $sYear Then ExitLoop

        ; Get week number
        $iWeek = _WeekNumberISO($sYear, $asDatePart[2], $asDatePart[3])

        ; Adjust to cover final part of previous Week 52 if required
        If $fStart Then
            If $iWeek >= 52 Then $iWeek = 0
        Else
            If $iWeek = 1 Then $iWeek = 53
        EndIf
        ; Reset flag if past initial week
        If $iWeek = 2 Then $fStart = False

        ; Get day of week and adjust for Sunday
        $iIndex = _DateToDayOfWeek($sYear, $asDatePart[2], $asDatePart[3])
        If $iIndex = 1 Then
            $iIndex = 8
            ; Adjust for final week if needed
            If Not $fStart And $iWeek = 53 Then $iWeek = 52
        EndIf

        ; Fill array
        $aWeeks[$iWeek][$iIndex - 1] = $aDays[$iIndex - 1] & " " & $asDatePart[3] & " " & $aMonths[$asDatePart[2]]
        ; Move to next day
        $sdate = _DateAdd("d", 1, $sdate)
    WEnd

    ; Check if weeks 0 and 53 are used
    For $i = 1 To 6
        If $aWeeks[0][$i] <> "" Then $fWeek_0 = True
        If $aWeeks[53][$i] <> "" Then $fWeek_53 = True
    Next
    ; If not then do not display them if selected
    If GUICtrlRead($hTab) = 0 And Not $fWeek_0 Then _GUICtrlTab_ClickTab($hTab, 1)
    If GUICtrlRead($hTab) = 53 And Not $fWeek_53 Then _GUICtrlTab_ClickTab($hTab, 52)
    $clickedweek = GUICtrlRead($hTab)

    For $i = 1 To 6
        ConsoleWrite($aDayLabels[$i] & " - " & $aWeeks[$clickedweek][$i] & @CRLF)
        GUICtrlSetData($aDayLabels[$i], $aWeeks[$clickedweek][$i])
    Next

EndFunc   ;==>_Calculate

Still waiting for the search code! :nuke:

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

the search code will not come.

because that was a question for a other project.

not for this one.

so i'm working on it now.

however i found out that now i cant type in the box anymore.

- i'm working on it to fix that.

- when i edited a listview row i cant see anymore wich listview has been edited in the past that was consolewrited. i'm working to fix that.

- and wich year ofcourse.

i shall explane the prepose of this program.

i'm going to build some mysql support in it.

the target is that multiple users can use this program.

and that what they do with the listview that is going to be stored in the mysql database.

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...