Jump to content

GUICtrlCreateMonthCal selecting multiple dates


Recommended Posts

It is fairly simple to select a contiguous range using the MonthCalendar control (see the _GUICtrlMonthCal_SetSelRange) example, Dates with gaps doesn't seem easy.  Also, from what I am reading, there is no simple way to maintain selections if the MonthCalendar control is changed. 

You might consider having other means to collect the desired dates external to the control (i.e. an array, a listbox, etc.).

 

Looking at some of the API calls, you could probably get really clever and use SetDayState and GetDayState to do something like you want, but it is going to get complicated.

Edited by spudw2k
Link to comment
Share on other sites

Okay, I tried a listview, but how do I read what the user selected in the listview?  GuiCtrlRead doesn't seem to do the job.

 

Func _Okay()
    Local $aListViewData = GUICtrlRead($g_hListView, 0)
    _ArrayDisplay($aListViewData)
;~  ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sListViewData = ' & $sListViewData & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

EndFunc   ;==>_MoveRight

 

 

The rest of the code...  

 

#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <Date.au3>

Opt("GUIOnEventMode", 1)
Global $g_hListView, $g_hListView2, $g_hGUI1, $g_hGUI2, $g_iRun = 1
Global $g_iDock = 1, $g_iDock_Location = 1, $g_iX1, $g_iX2, $g_iY1, $g_iY2
Global $g_idOptionsItem2, $g_idOptionsItem3, $g_idOptionsItem4
Global $g_idOptions2Item2, $g_idOptions2Item3, $g_idOptions2Item4

Example()

Func Example()
    $g_iRun = 1
    Local $idOptionsMenu, $idOptionsItem1, $idOptions2Menu, $idOptions2Item1, $iWidth = 800
    Local $id_MoveLeft, $id_MoveRight, $id_Exit1, $id_Exit2
    Local $id_CopyRight, $id_CopyLeft, $hImage
    Local $iStylesEx = BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES, $LVS_EX_SUBITEMIMAGES)

    $g_hGUI1 = GUICreate("(External) ListView Copy Items", $iWidth, 800, 5, 5)
    GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
    GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")
    GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")

    ; need the handle because UDF function(s) are used to create the items
    $g_hListView = GUICtrlGetHandle(GUICtrlCreateListView("", 20, 20, 200, 700, BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE))
    _GUICtrlListView_SetExtendedListViewStyle($g_hListView, $iStylesEx)
    $g_hListView2 = GUICtrlGetHandle(GUICtrlCreateListView("", 300, 20, 200, 268, BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE))
    _GUICtrlListView_SetExtendedListViewStyle($g_hListView2, $iStylesEx)

    $id_MoveRight = GUICtrlCreateButton("Move", 600, 50, 90, 50)
    GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
    GUICtrlSetOnEvent($id_MoveRight, "_MoveRight")

    $id_Okay = GUICtrlCreateButton("Okay", 600, 100, 90, 50)
    GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
    GUICtrlSetOnEvent($id_Okay, "_Okay")

;~  GUISetState(@SW_SHOW, $g_hGUI2)
    GUISetState(@SW_SHOW, $g_hGUI1)

    ; Add columns
    _GUICtrlListView_AddColumn($g_hListView, "Days of the Month", 120)

    ; Add columns
    _GUICtrlListView_AddColumn($g_hListView2, "Days of the Month", 120)

    ; Add items
    Local $aWhichDaysTheClerksMightBeWorking = _DetermineClerkPayDates()
    For $iCC = 1 To UBound($aWhichDaysTheClerksMightBeWorking) - 1
        _GUICtrlListView_AddItem($g_hListView, $aWhichDaysTheClerksMightBeWorking[$iCC])
    Next

    While $g_iRun
        If $g_iDock Then _KeepWindowsDocked()
        Sleep(10)
    WEnd
EndFunc   ;==>Example

Func _KeepWindowsDocked()
    Local $a_PosWin1 = WinGetPos($g_hGUI1)
;~  Local $a_PosWin2 = WinGetPos($g_hGUI2)
    If $g_iDock_Location == 1 Then
        If (($a_PosWin1[0] <> $g_iX1 Or $a_PosWin1[1] <> $g_iY1) And BitAND(WinGetState($g_hGUI1), 8) Or $g_iDock = 2) Then
            $g_iX1 = $a_PosWin1[0]
            $g_iY1 = $a_PosWin1[1]
            $g_iX2 = $a_PosWin1[2] + $g_iX1
            $g_iY2 = $g_iY1
;~          WinMove($g_hGUI2, "", $g_iX2, $g_iY2)
            $g_iDock = 1
;~      ElseIf (($a_PosWin2[0] <> $g_iX2 Or $a_PosWin2[1] <> $g_iY2) And BitAND(WinGetState($g_hGUI2), 8)) Then
;~          $g_iX2 = $a_PosWin2[0]
;~          $g_iY2 = $a_PosWin2[1]
;~          $g_iX1 = $a_PosWin2[0] - $a_PosWin1[2]
;~          $g_iY1 = $g_iY2
;~          WinMove($g_hGUI1, "", $g_iX1, $g_iY1)
        EndIf
    Else
        If (($a_PosWin1[0] <> $g_iX1 Or $a_PosWin1[1] <> $g_iY1) And BitAND(WinGetState($g_hGUI1), 8) Or $g_iDock = 2) Then
            $g_iX1 = $a_PosWin1[0]
            $g_iY1 = $a_PosWin1[1]
            $g_iX2 = $g_iX1
            $g_iY2 = $a_PosWin1[3] + $g_iY1
;~          WinMove($g_hGUI2, "", $g_iX2, $g_iY2)
            $g_iDock = 1
;~      ElseIf (($a_PosWin2[0] <> $g_iX2 Or $a_PosWin2[1] <> $g_iY2) And BitAND(WinGetState($g_hGUI2), 8)) Then
;~          $g_iX2 = $a_PosWin2[0]
;~          $g_iY2 = $a_PosWin2[1]
;~          $g_iX1 = $g_iX2
;~          $g_iY1 = $a_PosWin2[1] - $a_PosWin1[3]
;~          WinMove($g_hGUI1, "", $g_iX1, $g_iY1)
        EndIf
    EndIf
EndFunc   ;==>_KeepWindowsDocked

Func _Okay()
    Local $aListViewData = GUICtrlRead($g_hListView, 0)
    _ArrayDisplay($aListViewData)
;~  ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sListViewData = ' & $sListViewData & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

EndFunc   ;==>_MoveRight

Func _MoveRight()
    _GUICtrlListView_CopyItems($g_hListView, $g_hListView2, 1)
EndFunc   ;==>_MoveRight

Func _MoveLeft()
    _GUICtrlListView_CopyItems($g_hListView2, $g_hListView, 1)
EndFunc   ;==>_MoveLeft

Func _Exit()
    $g_iRun = 0
    GUIDelete($g_hGUI2)
    GUIDelete($g_hGUI1)
EndFunc   ;==>_Exit

Func SpecialEvents()
    Select
        Case @GUI_CtrlId = $GUI_EVENT_CLOSE
            _Exit()
    EndSelect
EndFunc   ;==>SpecialEvents

Func _DetermineClerkPayDates()

    Local $iNumOfDaysInCurrentMonth = _DateDaysInMonth(@YEAR, @MON)
    Local $aDaysOfTheMonthToReturn[0]

    For $iCC = 1 To $iNumOfDaysInCurrentMonth
        Local $iWeekday = _DateToDayOfWeekISO(@YEAR, @MON, $iCC)
        ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $iWeekday = ' & $iWeekday & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
        Switch $iWeekday
            Case 1 To 5
                Local $sDateToAdd = $iCC
                _ArrayAdd($aDaysOfTheMonthToReturn, $sDateToAdd)
        EndSwitch
    Next
;~  Return _ArrayToString($aDaysOfTheMonthToReturn, "|")
    Return $aDaysOfTheMonthToReturn

EndFunc   ;==>_DetermineClerkPayDates

 

Link to comment
Share on other sites

Try this :

Func _Okay()
  Local $iNum = _GUICtrlListView_GetItemCount ($g_hListView2)
  Local $aItem [$iNum]
  For $i = 0 to $iNum-1
    $aItem[$i] = _GUICtrlListView_GetItemText($g_hListView2, $i)
  Next
  _ArrayDisplay ($aItem)
EndFunc   ;==>_Okay

 

Link to comment
Share on other sites

For a listview, if you want to read what's selected you need to use 

$sListview = GUICtrlRead(GUICtrlRead($g_HListview))

Also, that returns a string, not an array.

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

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