Jump to content

Changing cell or item in listview


Recommended Posts

Hello,

I am trying to make a listview and then change only 1 cell-item in the listview

(similar like changing a cell in Excel, highlite it, then change it and save it when you click on another cell)

I looked in the forum, but I can only find a way wich selects the whole row of a listview and then it tells me what the items in the listview are.

Like in Excel I would like to make some cells editable and some not

Example:

Year---holiday-------------date----------weekday ; header of the listview

2014---newyear-----------1-januari----wednesday  ; only 2014 should be editable, the other three cells are not editable, wendsday is filled in by the program

2014---easter monday---1-april-------monday       ; 2014 and 1-april should be editable, the rest is filled by the programm

etc

I have been searching the forum, but cannot find anything which could help me on my way.

Perhaps I used the wrong keywords.

Anyone having suggestions?

Link to comment
Share on other sites

Have a look at:

_GUICtrlListView_GetSelectedIndices()

;)

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

Hi MikahS,

OK, that could be someting, I'm gooing to try this.

Hi Computergroove,

The date data are (for some holidays) not always the same, so I put them in by hand.

The weekdays are found by the functions: _Isoweeknumber, _DataFromWeeknumber which I found in the forum

Thanks for the tip, I will search also in the GUI forum.

Link to comment
Share on other sites

Any chance we could have a look at something you have tried?

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

Hi there,

This is the code I have up to now.

It needs some error handling, but it works.

The standard holidays could perhaps be imported in a similar way as in outlook.

Perhaps anyone knows the name of the file outlook uses?

Everybody thanks for their assistance 

#include <GuiConstants.au3>
#include <GuiEdit.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <WinAPI.au3>
#include <Date.au3>

; original code from BugFix and M4nOx june 2013


Opt("GuiCloseOnESC", 0)

Global $hEdit, $hDC, $hBrush, $Item = -1, $SubItem = 0
Global $hlistview

Global $Style = BitOR($WS_CHILD, $WS_VISIBLE, $ES_AUTOHSCROLL, $ES_LEFT)

$hGUI = GUICreate("ListView Subitems edit in place", 500, 280)

$hNM_DBCLK = GUICtrlCreateDummy()
$hEN_KILLFOCUS = GUICtrlCreateDummy()


Global $Day=@MDAY,$Month=@MON,$Year=@YEAR,$weekstart=0,$iWeekNum,$iName

createlistview()
filllistview()

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

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        case $hNM_DBCLK
            Start_EditingLV()
        ;Case $hEN_KILLFOCUS
         ;   End_EditingLV()
    EndSwitch
WEnd

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
Local $tNMHDR, $hWndFrom, $iCode

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

Switch $hWndFrom
Case $hListView
Switch $iCode
Case $NM_DBLCLK
                    GUICtrlSendToDummy($hNM_DBCLK)
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc

Func FrameRect($hDC, $nLeft, $nTop, $nRight, $nBottom, $hBrush)


Local $stRect = DllStructCreate("int;int;int;int")

DllStructSetData($stRect, 1, $nLeft)
DllStructSetData($stRect, 2, $nTop)
DllStructSetData($stRect, 3, $nRight)
DllStructSetData($stRect, 4, $nBottom)

DllCall("user32.dll", "int", "FrameRect", "hwnd", $hDC, "ptr", DllStructGetPtr($stRect), "hwnd", $hBrush)
EndFunc

Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
Local $iCode = BitShift($wParam, 16)

Switch $lParam
Case $hEdit
Switch $iCode
Case $EN_KILLFOCUS
                    GUICtrlSendToDummy($hEN_KILLFOCUS)
EndSwitch
EndSwitch

Return $GUI_RUNDEFMSG
EndFunc

Func Start_EditingLV()
    ControlDisable($hGUI, "", HWnd(_GUICtrlListView_GetHeader($hListView)))

    Local $aHit = _GUICtrlListView_SubItemHitTest($hListView)
    Local $hRect = ControlGetPos($hGUI, "", $hListView)

    If ($aHit[0] <> -1) And ($aHit[1] = 0) Then
        $Item = $aHit[0]
        $SubItem = 0
        Local $aRect = _GUICtrlListView_GetItemRect($hListView, $Item)
    ElseIf ($aHit[0] <> -1) And ($aHit[1] > 0) Then
        $Item = $aHit[0]
        $SubItem = $aHit[1]
        Local $aRect = _GUICtrlListView_GetSubItemRect($hListView, $Item, $SubItem)
    Else
        Return $GUI_RUNDEFMSG
    EndIf

    Local $iItemText = _GUICtrlListView_GetItemText($hListView, $Item, $SubItem)
    Local $iLen = _GUICtrlListView_GetStringWidth($hListView, $iItemText)
    $hEdit = _GUICtrlEdit_Create($hGUI, $iItemText, $aRect[0] + ($hRect[0] + 3), $aRect[1] + $hRect[1], $iLen + 10, 17, $Style)

    _GUICtrlEdit_SetSel($hEdit, 0, -1)
    _WinAPI_SetFocus($hEdit)
    $hDC = _WinAPI_GetWindowDC($hEdit)
    $hBrush = _WinAPI_CreateSolidBrush(0x0000FF)
    FrameRect($hDC, 0,0, $iLen + 10 , 17, $hBrush)
    HotKeySet("{ENTER}", "End_EditingLV")

EndFunc
Func End_EditingLV()
    Local $iText = _GUICtrlEdit_GetText($hEdit)
    Local $iItemText_year = _GUICtrlListView_GetItemText($hListView, $Item, 0)
    Local $iItemText_day = _GUICtrlListView_GetItemText($hListView, $Item, 1)
    Local $iItemText_date = _GUICtrlListView_GetItemText($hListView, $Item, 2)
    Local $iItemText_weeknumber = _GUICtrlListView_GetItemText($hListView, $Item, 3)
    Local $iItemText_weekday = _GUICtrlListView_GetItemText($hListView, $Item, 4)
    if $SubItem=0 Then; the year was edited
        $Year=$iText
        $Month=StringRight($iItemText_date,2)
        $Day=StringLeft($iItemText_date,2)
        $weekstart=0
        week_and_day($iName); this will return the weeknumber and the name of the day of the week
         _GUICtrlListView_SetItemText($hListView, $Item, $iText, 0); placing the right year
         _GUICtrlListView_SetItemText($hListView, $Item, $iWeekNum, 3); placing the right week number
         _GUICtrlListView_SetItemText($hListView, $Item, $iName, 4); placing the right name of the day
    EndIf
    if $SubItem=2 Then; the date was edited
        $Month=StringRight($iText,2)
        $Day=StringLeft($iText,2)
        if $Month<=0 or $Month>12 Then
            MsgBox(0,"Error","Date format should be dd-mm"&@CRLF&"Please try again")
            $Month=StringRight($iItemText_date,2)
            $Day=StringLeft($iItemText_date,2)
        EndIf
        if $Day<=0 or $Day>31 Then
            MsgBox(0,"Error","Date format should be dd-mm"&@CRLF&"Please try again")
            $Month=StringRight($iItemText_date,2)
            $Day=StringLeft($iItemText_date,2)
        EndIf
        $Year=$iItemText_year
        $weekstart=0
        week_and_day($iName); this will return the iweeknumber and the iname of the day of the week
         _GUICtrlListView_SetItemText($hListView, $Item, $Day&"-"&$Month, 2); placing the right date
         _GUICtrlListView_SetItemText($hListView, $Item, $iWeekNum, 3); placing the right week number
         _GUICtrlListView_SetItemText($hListView, $Item, $iName, 4); placing the right name of the day
    EndIf

    _WinAPI_DeleteObject($hBrush)
    _WinAPI_ReleaseDC($hEdit, $hDC)
    _WinAPI_DestroyWindow($hEdit)
    ControlEnable($hGUI, "", HWnd(_GUICtrlListView_GetHeader($hListView)))

    $Item = -1
    $SubItem = 0
    HotKeySet("{ENTER}")
EndFunc
func createlistview()
    $hListView = _GUICtrlListView_Create($hGUI, "", 10, 20, 600, 250)
    ; Add columns
    _GUICtrlListView_AddColumn($hlistview, "Year", 100)
    _GUICtrlListView_AddColumn($hlistview, "Holiday", 100)
    _GUICtrlListView_AddColumn($hlistview, "Date", 100)
    _GUICtrlListView_AddColumn($hlistview, "WeekNumber", 100)
    _GUICtrlListView_AddColumn($hlistview, "Weekday", 100)
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_AUTOARRANGE,$LVS_EX_FULLROWSELECT,$LVS_EX_DOUBLEBUFFER,$LVS_EX_SUBITEMIMAGES))
EndFunc
func filllistview()

    _GUICtrlListView_AddItem($hListView, "2014")
    _GUICtrlListView_AddSubItem($hListView, 0, "New Year", 1)
    _GUICtrlListView_AddSubItem($hListView, 0, "01-01", 2)
    _GUICtrlListView_AddSubItem($hListView, 0, "1", 3)
    _GUICtrlListView_AddSubItem($hListView, 0, "unknown", 4)

    _GUICtrlListView_AddItem($hListView, "2014")
    _GUICtrlListView_AddSubItem($hListView, 1, "Easter monday", 1)
    _GUICtrlListView_AddSubItem($hListView, 1, "01-04", 2)
    _GUICtrlListView_AddSubItem($hListView, 1, "1", 3)
    _GUICtrlListView_AddSubItem($hListView, 1, "unknown", 4)

    _GUICtrlListView_AddItem($hListView, "2014")
    _GUICtrlListView_AddSubItem($hListView, 2, "Kingsday", 1)
    _GUICtrlListView_AddSubItem($hListView, 2, "29-04", 2)
    _GUICtrlListView_AddSubItem($hListView, 2, "1", 3)
    _GUICtrlListView_AddSubItem($hListView, 2, "unknown", 4)

EndFunc
func week_and_day(ByRef $iName)
$iWeekNum =_ISOWeekNumber($Day, $Month, $Year, $WeekStart); het huidige weeknummer
$s = _DateFromWeekNumber($Year, $iWeekNum)
$sDates = _DateFormat($s, "dd-MM-yyyy")
For $i = 1 To 6
    $sDates &= "|" & _DateFormat(_DateAdd("D", $i, $s), "dd-MM-yyyy")
Next
$aDates = StringSplit($sDates, "|", 2); the real date
For $i = 0 To 6
    if StringLeft($aDates[$i],2)=$Day Then
        $iName=_DateDayOfWeek($i+1)
    EndIf
Next
EndFunc

Func _ISOWeekNumber($Day, $Month, $Year, $WeekStart)
    local $firstDay
    Local $diff
    Local $FirstWeekStart

; Check for erroneous input in $Day, $Month & $Year
    If  $Day > 31 or $Day < 1 Then
        SetError(1)
        Return -1
    ElseIf $Month > 12 or $Month < 1 Then
        SetError(1)
        Return -1
    ElseIf $Year < 1 or $Year > 2999 Then
        SetError(1)
        Return -1
    EndIf

; check if $WeekStart parameter is ok (= Sun / Mon)
    If Not IsInt($WeekStart) Or $WeekStart > 1 or $WeekStart < 0 Then
        $WeekStart = 0
        SetError(99)
    EndIf

; Find out the first day of real week 1
    $firstDay = _dateToDayOfWeek($Year, 1, 1)

    If $firstDay = 1 Then
        $diff = 1 - $firstDay + $WeekStart
    ElseIf  $firstDay = 2 Then
        $diff = 1 - $firstDay + $WeekStart
    ElseIf $firstDay <= 5 Then
        $diff = 1-$firstDay + $WeekStart
    ElseIf $firstDay > 5 Then
        $diff = 7 - ($firstDay -1) + $WeekStart

    EndIf

    $FirstWeekStart = _DateAdd ( 'd', $diff, $Year & "/01/01")

; Compare to real first day of week 1 and find out the difference in weeks
    If _DateDiff('d', $FirstWeekStart, $Year & "/" & $Month & "/" & $Day) >= 0 Then
        return _DateDiff( 'w',$FirstWeekStart, $Year & "/" & $Month & "/" & $Day) +1
    Else
        return _DateDiff( 'w',$Year-1 & "/01/01", $Year & "/" & $Month & "/" & $Day)
    EndIf

Endfunc
; The week with the first Thursday of the year is week number 1.
;Returns the date of the Monday of the week number.
Func _DateFromWeekNumber($iYear, $iWeekNum)
    Local $Date, $sFirstDate = _DateToDayOfWeek($iYear, 1, 1)
    If $sFirstDate < 6 Then
        $Date = _DateAdd("D", 2 - $sFirstDate, $iYear & "/01/01")
    ElseIf $sFirstDate = 6 Then
        $Date = _DateAdd("D", $sFirstDate - 3, $iYear & "/01/01")
    ElseIf $sFirstDate = 7 Then
        $Date = _DateAdd("D", $sFirstDate - 5, $iYear & "/01/01")
    EndIf
    Local $aDate = StringSplit($Date, "/", 2)
    Return _DateAdd("w", $iWeekNum - 1, $aDate[0] & "/" & $aDate[1] & "/" & $aDate[2])
EndFunc   ;==>_DateFromWeekNumber


; Format date
; $sDate, input date in the format yyyy/MM/dd[ hh:mm:ss]
Func _DateFormat($sDate, $sFormat)
    local $hGui = GUICreate("")
    local $idDate = GUICtrlCreateDate($sDate, 10, 10)
    GUICtrlSendMsg($idDate, 0x1032, 0, $sFormat) ; or "dddd, MMMM d, yyyy hh:mm:ss tt"); or "hh:mm tt"
    local $FormatedDate = GUICtrlRead($idDate)
    GUIDelete($hGui)
    Return $FormatedDate
EndFunc   ;==>_DateFormat
Link to comment
Share on other sites

  • Moderators

albertmaathuis,

Look at my GUIListViewEx UDF (the link is in my sig) - it allows you to edit ListView cells very easily. :)

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,

Thanks Melba23 your UDF is really easier and it gives much more possibilities

I made the same version with your UDF.

The code is below.

There is only one thing wich I couldn't figure out.

When e.g. I type the same year of date in a cell the  "$aRet = _GUIListViewEx_EditOnClick($iEditMode)" returns an array of only 1 line instead of two lines.

Is there a check on the string in the cell in your UDF?

And if so, is there a way that I can check if the returned array has more then one line? 

#include <GuiConstants.au3>
#include <GuiEdit.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <WinAPI.au3>
#include <Date.au3>
#include "GUIListViewEx.au3"
#include <GuiConstantsEx.au3>


Opt("GuiCloseOnESC", 0)

Global $aListview, $aRet, $iEditMode =0

Global $hEdit, $hDC, $hBrush, $Item = -1, $SubItem = 0
Global $hlistview

;Global $Style = BitOR($WS_CHILD, $WS_VISIBLE, $ES_AUTOHSCROLL, $ES_LEFT)

$hGUI = GUICreate("holidays listview editable/ sortable", 500, 280)

;$hNM_DBCLK = GUICtrlCreateDummy()
;$hEN_KILLFOCUS = GUICtrlCreateDummy()


Global $Day=@MDAY,$Month=@MON,$Year=@YEAR,$weekstart=0,$iWeekNum,$iName

create_listview()
fill_listview()

GUISetState()

; Register for sorting, dragging and editing
_GUIListViewEx_MsgRegister()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

    $aRet = _GUIListViewEx_EditOnClick($iEditMode) ; Use combos to change EditMode
    ; Array only returned AFTER EditOnClick process - so check array exists
    If IsArray($aRet) Then
        ; Uncomment to see returned array
        ;_ArrayDisplay($aRet, @error)
        recalculate()

    EndIf

WEnd

func recalculate()
    local $OriginalDay,$OriginalMonth,$OriginalYear
    $iRow=$aRet[1][0]+1
    $iCol=$aRet[1][1]
    ; read first the original values
    $OriginalYear=$aListview[$iRow][0]
    $OriginalMonth=StringRight($aListview[$iRow][2],2)
    $OriginalDay=StringLeft($aListview[$iRow][2],2)
    ;now update the array with the edited value
    $aListview = _GUIListViewEx_ReadToArray($hListview, 1); update array

    if $iCol=0 Then; the year was edited
        $Year=$aListview[$iRow][0]
        $Month=StringRight($aListview[$iRow][2],2)
        $Day=StringLeft($aListview[$iRow][2],2)
        $weekstart=0
        week_and_day($iName); this will return the weeknumber and the name of the day of the week
        $aListview[$iRow][3]=$iWeekNum; placing the right week number in the array
        $aListview[$iRow][4]=$iName; placing the right name of the day in the array
         _GUICtrlListView_SetItemText($hListView, $iRow-1, $iWeekNum, 3); placing the right week number
         _GUICtrlListView_SetItemText($hListView, $iRow-1, $iName, 4); placing the right name of the day
    EndIf
    if $iCol=2 Then; the date was edited
        $Month=StringRight($aListview[$iRow][2],2)
        $Day=StringLeft($aListview[$iRow][2],2)
        if $Month<=0 or $Month>12 Then
            MsgBox(0,"Error","Date format should be dd-mm"&@CRLF&"Please try again")
            $Month=$OriginalMonth
            $Day=$OriginalDay
        EndIf
        if $Day<=0 or $Day>31 Then
            MsgBox(0,"Error","Date format should be dd-mm"&@CRLF&"Please try again")
            $Month=$OriginalMonth
            $Day=$OriginalDay
        EndIf
        $Year=$OriginalYear
        $weekstart=0
        $iName=""
        week_and_day($iName); this will return the weeknumber and the name of the day of the week


        $aListview[$iRow][2]=$Day&"-"&$Month; placing the right date in the array
        $aListview[$iRow][3]=$iWeekNum; placing the right week number in the array
        $aListview[$iRow][4]=$iName; placing the right name of the day in the array
         _GUICtrlListView_SetItemText($hListView, $iRow-1, $Day&"-"&$Month, 2); placing the right date
         _GUICtrlListView_SetItemText($hListView, $iRow-1, $iWeekNum, 3); placing the right week number
         _GUICtrlListView_SetItemText($hListView, $iRow-1, $iName, 4); placing the right name of the day
    EndIf

EndFunc


func create_listview()

    $hListview = _GUICtrlListView_Create($hGUI, "", 10, 20, 600, 250, BitOR($LVS_DEFAULT, $WS_BORDER))
    _GUICtrlListView_SetExtendedListViewStyle($hListview, $LVS_EX_FULLROWSELECT)
    ; Add columns
    _GUICtrlListView_AddColumn($hlistview, "Year", 100)
    _GUICtrlListView_AddColumn($hlistview, "Holiday", 100)
    _GUICtrlListView_AddColumn($hlistview, "Date", 100)
    _GUICtrlListView_AddColumn($hlistview, "WeekNumber", 100)
    _GUICtrlListView_AddColumn($hlistview, "Weekday", 100)

    _GUICtrlListView_SetTextBkColor($hListview, 0xDDFFDD)

EndFunc
func fill_listview()

    _GUICtrlListView_AddItem($hListView, "2014")
    _GUICtrlListView_AddSubItem($hListView, 0, "New Year", 1)
    _GUICtrlListView_AddSubItem($hListView, 0, "01-01", 2)
    _GUICtrlListView_AddSubItem($hListView, 0, "1", 3)
    _GUICtrlListView_AddSubItem($hListView, 0, "unknown", 4)

    _GUICtrlListView_AddItem($hListView, "2014")
    _GUICtrlListView_AddSubItem($hListView, 1, "Easter monday", 1)
    _GUICtrlListView_AddSubItem($hListView, 1, "01-04", 2)
    _GUICtrlListView_AddSubItem($hListView, 1, "1", 3)
    _GUICtrlListView_AddSubItem($hListView, 1, "unknown", 4)

    _GUICtrlListView_AddItem($hListView, "2014")
    _GUICtrlListView_AddSubItem($hListView, 2, "Kingsday", 1)
    _GUICtrlListView_AddSubItem($hListView, 2, "29-04", 2)
    _GUICtrlListView_AddSubItem($hListView, 2, "1", 3)
    _GUICtrlListView_AddSubItem($hListView, 2, "unknown", 4)

    ; Read array from Right  ListView
    $aListview = _GUIListViewEx_ReadToArray($hListview, 1)


    $iLV_Index = _GUIListViewEx_Init($hListview, $aListview, 1, 0xFF0000, True, 2 + 4 + 8 + 16,"*")

EndFunc
func week_and_day(ByRef $iName)
    Local $s,$sDates
$iWeekNum =_ISOWeekNumber($Day, $Month, $Year, $WeekStart); het huidige weeknummer
$s = _DateFromWeekNumber($Year, $iWeekNum)
$sDates = _DateFormat($s, "dd-MM-yyyy")
For $i = 1 To 6
    $sDates &= "|" & _DateFormat(_DateAdd("D", $i, $s), "dd-MM-yyyy")
Next

$aDates = StringSplit($sDates, "|", 2); the real date
For $i = 0 To 6
    if StringLeft($aDates[$i],2)=$Day Then
        $iName=_DateDayOfWeek($i+2)
    EndIf
Next
EndFunc

Func _ISOWeekNumber($Day, $Month, $Year, $WeekStart)
    local $firstDay
    Local $diff
    Local $FirstWeekStart

; Check for erroneous input in $Day, $Month & $Year
    If  $Day > 31 or $Day < 1 Then
        SetError(1)
        Return -1
    ElseIf $Month > 12 or $Month < 1 Then
        SetError(1)
        Return -1
    ElseIf $Year < 1 or $Year > 2999 Then
        SetError(1)
        Return -1
    EndIf

; check if $WeekStart parameter is ok (= Sun / Mon)
    If Not IsInt($WeekStart) Or $WeekStart > 1 or $WeekStart < 0 Then
        $WeekStart = 0
        SetError(99)
    EndIf

; Find out the first day of real week 1
    $firstDay = _dateToDayOfWeek($Year, 1, 1)

    If $firstDay = 1 Then
        $diff = 1 - $firstDay + $WeekStart
    ElseIf  $firstDay = 2 Then
        $diff = 1 - $firstDay + $WeekStart
    ElseIf $firstDay <= 5 Then
        $diff = 1-$firstDay + $WeekStart
    ElseIf $firstDay > 5 Then
        $diff = 7 - ($firstDay -1) + $WeekStart

    EndIf

    $FirstWeekStart = _DateAdd ( 'd', $diff, $Year & "/01/01")

; Compare to real first day of week 1 and find out the difference in weeks
    If _DateDiff('d', $FirstWeekStart, $Year & "/" & $Month & "/" & $Day) >= 0 Then
        return _DateDiff( 'w',$FirstWeekStart, $Year & "/" & $Month & "/" & $Day) +1
    Else
        return _DateDiff( 'w',$Year-1 & "/01/01", $Year & "/" & $Month & "/" & $Day)
    EndIf

Endfunc
; The week with the first Thursday of the year is week number 1.
;Returns the date of the Monday of the week number.
Func _DateFromWeekNumber($iYear, $iWeekNum)
    Local $Date, $sFirstDate = _DateToDayOfWeek($iYear, 1, 1)
    If $sFirstDate < 6 Then
        $Date = _DateAdd("D", 2 - $sFirstDate, $iYear & "/01/01")
    ElseIf $sFirstDate = 6 Then
        $Date = _DateAdd("D", $sFirstDate - 3, $iYear & "/01/01")
    ElseIf $sFirstDate = 7 Then
        $Date = _DateAdd("D", $sFirstDate - 5, $iYear & "/01/01")
    EndIf
    Local $aDate = StringSplit($Date, "/", 2)
    Return _DateAdd("w", $iWeekNum - 1, $aDate[0] & "/" & $aDate[1] & "/" & $aDate[2])
EndFunc   ;==>_DateFromWeekNumber


; Format date
; $sDate, input date in the format yyyy/MM/dd[ hh:mm:ss]
Func _DateFormat($sDate, $sFormat)
    local $hGui = GUICreate("")
    local $idDate = GUICtrlCreateDate($sDate, 10, 10)
    GUICtrlSendMsg($idDate, 0x1032, 0, $sFormat) ; or "dddd, MMMM d, yyyy hh:mm:ss tt"); or "hh:mm tt"
    local $FormatedDate = GUICtrlRead($idDate)
    GUIDelete($hGui)
    Return $FormatedDate
EndFunc   ;==>_DateFormat 

bilities then my first code.

Link to comment
Share on other sites

  • Moderators

albertmaathuis,

I think you have misunderstood the content of the array returned from _GUIListViewEx_EditOnClick. As your code stands, you will exit the editing process after each edit and the array will only ever hold a single element coordinate:

1     .
Row   Col
If you want to be able to edit more than one item, you need to set the $iEditMode parameter to allow for multiple edits in one pass - and set the correct $sCols parameter when initialising the ListView to get only certain columns to be editable. I changed your code as followsL

; Line 14
Global $aListview, $aRet, $iEditMode = 33
; This edit mode allows you to loop around the editable elements - only Enter or Esc will end the edit process

; Line 144
$iLV_Index = _GUIListViewEx_Init($hlistview, $aListview, 1, 0xFF0000, True, 2 + 4, "0;2") 
; Only columns 0 and 2 editable - which is what you wanted
Now when I edit several items, I get an array with several sets of coordinates - like this:

3   .
0   0
2   0
2   0
You can see that the [0][0] element of the array indicates the number of edits that took place. The UDF does not return the content of the edited cells - it tells you which cells were edited and then it is up to the user to determine the content by examining the revised content of the ListView (use _GUIListViewEx_ReturnArray to get this in array form) and reading the relevant cells. ;)

Does all that make sense? Please ask again if not. :)

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

albertmaathuis,

Great - do not hesitate to ask if you run into any problems. :)

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

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