Jump to content

Edit In Place Listview (multi-column)


eltorro
 Share

Recommended Posts

I'm wanting to expand this to allow CheckBoxes. Is there a rhyme or reason for the control types being 2,4,1, and 256? I didn't want to mess something up.

Update:

128 was already in the code so I'm using that one for now (until I hear otherwise). I know it's outputting the direct value of the checkbox (which for some reason is 1 = checked and 4 = unchecked). Is there an easy way to mask this with say just 1 and 0 or different symbols?

Edited by JohnBailey
A decision is a powerful thing
Link to comment
Share on other sites

  • Replies 82
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

Updates I made to allow for Checkbox. I'd like to hear back from someone on what they think.

===============================================================================
; Function Name:    _LVUpdate
; Description:        Put the new data in the Listview
; Parameter(s):    $editCtrl         - IN/OUT -
;                        $LISTVIEWCTRL     - IN/OUT -
;                        $iRow                 - IN -
;                        $iCol                 - IN -
;
; Requirement(s):
; Return Value(s):
; User CallTip:
; Author(s):  $lvCheckBox by johnbailey don't get mad at Stephen Podhajecki, Gary Frost, or pdm for this addition sucking
; Note(s):
;===============================================================================
Func _LVUpdate(ByRef $editCtrl, ByRef $LISTVIEWCTRL, $iRow, $iCol)
    If $editCtrl = $lvCheckbox Then
        Local $CBstate = GUICtrlRead($editCtrl)
        If  $CBstate = 4 Then
            Local $newText = ' '
        ElseIf $CBstate = 1 THen
            Local $newText = 1
        EndIf
    Else 
        Local $newText = GUICtrlRead($editCtrl)
    EndIf
    Local $item = GUICtrlRead($LISTVIEWCTRL)
    _GUICtrlListViewSetItemText($LISTVIEWCTRL, $iRow, $iCol, $newText)
    _CancelEdit($LVcolControl)
EndFunc   ;==>_LVUpdate


;===============================================================================
; Function Name:    _TermEditLib
; Description:        Deletes the editing controls and un-registers WM_NOTIFY handler.
; Parameter(s):
;Requirement(s):
; Return Value(s):
; User CallTip:
; Author(s):
; Note(s):        Call this when close your gui if switching to another gui.
;===============================================================================
Func _TermEditLib()
    GUICtrlDelete($lvEdit)
    GUICtrlDelete($lvCombo)
    GUICtrlDelete($lvCheckbox)
    GUICtrlDelete($lvDate)
    GUIRegisterMsg($WM_NOTIFY, "")
   
EndFunc   ;==>_TermEditLib

;===============================================================================
; Function Name:    _InitEditLib
; Description:        Create the editing controls and registers WM_NOTIFY handler.
; Parameter(s):
; Requirement(s):
; Return Value(s):
; User CallTip:
; Author(s):
; Note(s):        Call this BEFORE you create your listview.
;===============================================================================
Func _InitEditLib($functionName="WM_Notify_Events_EditInPlaceStandard")
    $lvEdit = GUICtrlCreateInput("", 0, 0, 1, 1, BitOR($ES_AUTOHSCROLL, $ES_NOHIDESEL, $WS_BORDER), 0)
    GUICtrlSetState($lvEdit, $GUI_HIDE)
    GuiCtrlSetFont($lvEdit,8.5)
    $lvCombo = GUICtrlCreateCombo("", 0, 0, 1, 1)
    GUICtrlSetState($lvCombo, $GUI_HIDE)
    $lvDate = GUICtrlCreateDate("", 0, 0, 1, 1, $DTS_SHORTDATEFORMAT)
    GUICtrlSetState($lvDate, $GUI_HIDE)
    $lvCheckbox = GUICtrlCreateCheckbox('',0,0)
    GUIRegisterMsg($WM_NOTIFY, $functionName)
EndFunc   ;==>_InitEditLib

;===============================================================================
; Function Name:    _InitEdit
; Description:        Bring forth the editing control and set focus on it.
; Parameter(s):    $LVINFO             - IN -
;                        $LVcolControl    - IN -
;
; Requirement(s):
; Return Value(s):
; User CallTip:
; Author(s):
; Note(s):
;===============================================================================
Func _InitEdit($LVINFO, $LVcolControl)
    if $bCALLBACK Then
        _CancelEdit($LVcolControl)
        $bCALLBACK = False
    EndIf
   
    If $editFlag = 1 Then _CancelEdit($LVcolControl)
    Local $CtrlType
    If $LVINFO[0] < 0 Or $LVINFO[1] < 0 Then Return 0
    If UBound($LVcolControl) - 1 < $LVINFO[1] Then
        $CtrlType = 0
    Else
        $CtrlType = $LVcolControl[$LVINFO[1]]
    EndIf
    ;----------------------------------------------------------------------------------------------
    If $DebugIt Then ConsoleWrite(_DebugHeader("$CtrlType:" & $CtrlType))
    ;----------------------------------------------------------------------------------------------
    Switch $CtrlType
        Case 2
            $editCtrl = $lvCombo
        Case 4
            $editCtrl = $lvDate
        Case 1
            GUICtrlSetData($lvEdit, "")
            $editCtrl = $lvEdit
        Case 256
            $bCALLBACK= True
        Case 128
            $editCtrl = $lvCheckbox
        Case Else
            Return
    EndSwitch
    If $bCALLBACK Then
        Call($LVCALLBACK,$LVINFO)
        $bCALLBACK = False
    Else
        ;----------------------------------------------------------------------------------------------
        If $DebugIt Then ConsoleWrite(_DebugHeader("Classname="&_GetClassName($editCtrl)))
        ;----------------------------------------------------------------------------------------------
        GUICtrlSetPos($editCtrl, $LVINFO[2], $LVINFO[3], $LVINFO[4], $LVINFO[5])
        Local $oldText = _GUICtrlListViewGetItemText($LISTVIEWCTRL, $LVINFO[0], $LVINFO[1])
        GUICtrlSetData($editCtrl, $oldText)
        GUICtrlSetState($editCtrl, $GUI_SHOW)
        GUICtrlSetState($editCtrl, $GUI_FOCUS)
        $editFlag = 1
    EndIf
    sleep(1000)
EndFunc   ;==>_InitEdit
A decision is a powerful thing
Link to comment
Share on other sites

  • 2 weeks later...

special thanks for eltorro,

this is very good udf!!

i have one question:

can i receive the fields value, only of the checked item, when i press one control button ?

i work with this:

Func riceviDati()

        Local $a_Item = _GUICtrlListViewGetItemTextArray ($ListView, 0)
            If (Not IsArray($a_Item)) Then
            MsgBox(0,"","no array")
            Else
                For $i = 1 To $a_Item[0]
                    If $i == 10 Then $a_Item[$i] = GUICtrlRead($lvCombo)
                    MsgBox(0, "Passed Item Index only", "SubItem[" & $i & "] = " & $a_Item[$i])
                Next
            EndIf   
EndFunc

;in the main() func

        Global $riceviDati = GUICtrlCreateButton("Ricevi",30,$guih-40,100,25,0)
        GUICtrlSetOnEvent($riceviDati, "riceviDati")
Link to comment
Share on other sites

special thanks for eltorro,

this is very good udf!!

i have one question:

can i receive the fields value, only of the checked item, when i press one control button ?

i work with this:

Func riceviDati()

        Local $a_Item = _GUICtrlListViewGetItemTextArray ($ListView, 0)
            If (Not IsArray($a_Item)) Then
            MsgBox(0,"","no array")
            Else
                For $i = 1 To $a_Item[0]
                    If $i == 10 Then $a_Item[$i] = GUICtrlRead($lvCombo)
                    MsgBox(0, "Passed Item Index only", "SubItem[" & $i & "] = " & $a_Item[$i])
                Next
            EndIf   
EndFunc

;in the main() func

        Global $riceviDati = GUICtrlCreateButton("Ricevi",30,$guih-40,100,25,0)
        GUICtrlSetOnEvent($riceviDati, "riceviDati")
Id have to play with it awhile but it should be possible.
Link to comment
Share on other sites

This is probably going to be a stupid question...

Could DllCallBack (http://www.autoitscript.com/forum/index.php?showtopic=50768&st=0&p=384128&#entry384128) be used to enhance this udf? I may be completely off! haha, I probably am.

:nervous:

A decision is a powerful thing
Link to comment
Share on other sites

special thanks for eltorro,

this is very good udf!!

i have one question:

can i receive the fields value, only of the checked item, when i press one control button ?

i work with this:

Func riceviDati()

        Local $a_Item = _GUICtrlListViewGetItemTextArray ($ListView, 0)
            If (Not IsArray($a_Item)) Then
            MsgBox(0,"","no array")
            Else
                For $i = 1 To $a_Item[0]
                    If $i == 10 Then $a_Item[$i] = GUICtrlRead($lvCombo)
                    MsgBox(0, "Passed Item Index only", "SubItem[" & $i & "] = " & $a_Item[$i])
                Next
            EndIf   
EndFunc

;in the main() func

        Global $riceviDati = GUICtrlCreateButton("Ricevi",30,$guih-40,100,25,0)
        GUICtrlSetOnEvent($riceviDati, "riceviDati")
I was looking at this again and I not sure what it is that you want to do. From the array above, do you just want to know if the item is checked? Or, do you want to know if the clicked row is checked before getting the items?
Link to comment
Share on other sites

I did an adjustment to your script eltorro that retrieves the item clicked (a little vague in what I actually did - I can post it - not too good with explaining it). If that is what he's looking for

Did I pm you the updated scripts? If not, I updated the code and zip in the first post to address the problem with the listview on a tab.

Post what you have, and let's have a look.

Edited by eltorro
Link to comment
Share on other sites

Did I pm you the updated scripts? If not, I updated the code and zip in the first post to address the problem with the listview on a tab.

AWESOME!!! I had no idea! You rock

Post what you have, and let's have a look.

haha because of the update, now much my script will most likely need to be totally redone :)

A decision is a powerful thing
Link to comment
Share on other sites

If need be I can put together an example script.

Here's what I did (forgive me for any transgressions) :)

[autoit]#include-once

#include <GuiConstants.au3>

#include <GuiListview.au3>

#include <ControlConstants.au3>

; ------------------------------------------------------------------------------

;

; AutoIt Version: 3.0

; Language: English

; Description: Multi-column editable Listview (EditInPlace)

; Stephen Podhajecki <gehossafats at netmdc.com/> Gary Frost <gafrost at charter dot net/>

; pdm for control array concept

; see http://www.autoitscript.com/forum/index.ph...mp;#entry322551

;==============================================================================

; ######>>> set the type of control for each column <<<######

; 0 = Input/edit 1 = combobox 2 = date control

; Global $LVcolControl[4]=[0,0,1,2]

; _InitEditLib();######>>> add this before your ListView <<<######

; _MonitorEditState($Gui, $editCtrl, $editFlag, $LISTVIEWCTRL, $LVINFO, $LVcolControl);######>>> add this in your message loop<<<######

; _TermEditLib();######>>> add this after your message loop<<<######

; $LISTVIEWCTRL = $ListView1 ######>>> Set this to your ListView control <<<######

;==============================================================================

Global Const $DebugIt = 0

;~ Global Const $WM_NOTIFY = 0x004E

;Global $WM_KEYDOWN

;~ Global Const $NM_FIRST = 0

;~ Global Const $NM_CLICK = ($NM_FIRST - 2)

;~ Global Const $NM_DBLCLK = ($NM_FIRST - 3)

;~ Global Const $NM_RCLICK = ($NM_FIRST - 5)

;~ Global Const $NM_RDBLCLK = ($NM_FIRST - 6)

;~ Global Const $LVN_ENDLABELEDITA = (-106)

Global $LVCALLBACK = "_CancelEdit" ; default to cancel edit

Global $LVCONTEXT = "_CancelEdit" ; defalut to cancel edit

Global $bCALLBACK = False ;a call-back has been executed.

Global $b_LVUpdateLOSTFOCUS = False ;save editing if another cell is clicked

Global $bEDITondblclick = False ;Must dblclick to edit

Global $old_col

Global $LISTVIEWCTRL = -999

Global $Gui, $editFlag

Global $editCtrl ;= the CtrlId of the editing control.

;;array dim to number of cols, value of each element determines control.

Global $LVcolControl[1] = [0] ;0= ignore, 1= edit, 2= combo, 4= calendar, 256 use callback.

Global $LVcolRControl[1] = [0] ;0= ignore, 256 = context callback.

Global $EIP_ResetComboAfterClickDone = false ; typically used is different columns or rows in your LVs or multiple LVs (JohnBailey)

Global $lvEdit, $lvCombo, $lvDate, $lvCheckbox

Global $LVINFO[10];

Opt("GUICloseOnESC", 0);turn off exit on esc.

;===============================================================================

; Function Name: _EIPInitAllColumnClicksStandard

;

; Description: Initializes (sets up the arrays for) the column right and left clicks. Therefore, all columns will have the same functions.

;

; Parameter(s): $iaccsTotalColumns - number, The Number of Columns

; $iaccsLeftClickOption - number, Left Click option (default = 1)(other options = ;0= ignore, 1= edit, 2= combo, 4= calendar, 256= use callback)

; $iaccsRightClickOption - boolean, Right Click option (default = true)

;

; Requirement(s):

;

; Return Value(s): Sets Globals which are arrays

;

; User CallTip: _EIPInitAllColumnClicksStandard($iaccsTotalColumns[,$iaccsLeftClickOption=1][,$iaccsRightClickOption=256]). Sets up all columns with the same type of control.

;

; Note(s): This is optional and just sets up the array that is called

;

; Author(s): JohnBailey - myregistrationbox at gmail dot com

;===============================================================================

Func _EIPInitAllColumnClicksStandard($iaccsTotalColumns,$iaccsLeftClickOption=1,$iaccsRightClickOption=true)

; ======>>> set the type of control for each column <<<======

;0= ignore, 1= edit, 2= combo, 4= calendar, 256= use callback.

Local $iaccsCounter

Global $LVcolControl[$iaccsTotalColumns]; = [1,1,1,1] ;left click actions

For $iaccsCounter = 0 to $iaccsTotalColumns-1

$LVcolControl[$iaccsCounter] = $iaccsLeftClickOption

Next

;0 = ignore, 256= use context callback

Global $LVcolRControl[$iaccsTotalColumns] ;= [256,256,256,256] ; right click actions

For $iaccsCounter = 0 to $iaccsTotalColumns-1

If $iaccsRightClickOption Then

$LVcolRControl[$iaccsCounter] = 256

Else

$LVcolRControl[$iaccsCounter] = 0

EndIf

Next

EndFunc ;==>_EIPInitAllColumnClicksStandard

;===============================================================================

; Function Name: _InitEditLib

; Description: Create the editing controls and registers WM_NOTIFY handler.

; Parameter(s):

; Requirement(s):

; Return Value(s):

; User CallTip:

; Author(s):

; Note(s): Call this BEFORE you create your listview.

;===============================================================================

Func _InitEditLib($functionName="WM_Notify_Events_EditInPlaceStandard")

$lvEdit = GUICtrlCreateInput("", 0, 0, 1, 1, BitOR($ES_AUTOHSCROLL, $ES_NOHIDESEL, $WS_BORDER), 0)

GUICtrlSetState($lvEdit, $GUI_HIDE)

GuiCtrlSetFont($lvEdit,8.5)

$lvCombo = GUICtrlCreateCombo("", 0, 0, 1, 1)

GUICtrlSetState($lvCombo, $GUI_HIDE)

$lvDate = GUICtrlCreateDate("", 0, 0, 1, 1, $DTS_SHORTDATEFORMAT)

GUICtrlSetState($lvDate, $GUI_HIDE)

$lvCheckbox = GUICtrlCreateCheckbox('',0,0)

GUICtrlSetState($lvCheckBox, $GUI_HIDE)

GUIRegisterMsg($WM_NOTIFY, $functionName)

EndFunc ;==>_InitEditLib

;===============================================================================

; Function Name: _TermEditLib

; Description: Deletes the editing controls and un-registers WM_NOTIFY handler.

; Parameter(s):

;Requirement(s):

; Return Value(s):

; User CallTip:

; Author(s):

; Note(s): Call this when close your gui if switching to another gui.

;===============================================================================

Func _TermEditLib()

GUICtrlDelete($lvEdit)

GUICtrlDelete($lvCombo)

GUICtrlDelete($lvCheckbox)

GUICtrlDelete($lvDate)

GUIRegisterMsg($WM_NOTIFY, "")

EndFunc ;==>_TermEditLib

;===============================================================================

; Function Name: ListView_Click

; Description: Called from WN_NOTIFY event handler.

; Parameter(s):

; Requirement(s):

; Return Value(s):

; User CallTip:

; Author(s): Stephen Podhajecki <gehossafats at netmdc.com/>

; Note(s):

;===============================================================================

Func _ListView_Click()

;----------------------------------------------------------------------------------------------

If $DebugIt Then ConsoleWrite(_DebugHeader("$NM_CLICK"))

;----------------------------------------------------------------------------------------------

If $editFlag = 1 Then

If $b_LVUpdateLOSTFOCUS Then

If UBound($LVcolControl) - 1 < $LVINFO[1] Then

_CancelEdit()

Else

_LVUpdate($editCtrl, $LISTVIEWCTRL, $LVINFO[6], $LVINFO[7])

EndIf

Else

If UBound($LVcolControl) - 1 < $LVINFO[1] Then

_CancelEdit()

Else

If $LVcolControl[$LVINFO[1]] <> 0 Then

_LVUpdate($editCtrl, $LISTVIEWCTRL, $LVINFO[6], $LVINFO[7])

Else

_CancelEdit()

EndIf

EndIf

EndIf

Else

If $bEDITondblclick = False Then

_InitEdit($LVINFO, $LVcolControl)

Else

_CancelEdit($LVcolControl)

EndIf

EndIf

EndFunc ;==>ListView_Click

;===============================================================================

; Function Name: ListView_RClick

; Description: Called from WN_NOTIFY event handler.

; Parameter(s):

; Requirement(s):

; Return Value(s):

; User CallTip:

; Author(s): Stephen Podhajecki <gehossafats at netmdc.com/>

; Note(s):

;===============================================================================

Func _ListView_RClick()

If $editFlag = 1 Then

Return 0

Else

If $LVINFO[0] < 0 Or $LVINFO[1] < 0 Then Return 0

If $LVcolRControl[$LVINFO[1]] = 256 Then Call($LVCONTEXT,$LVINFO) ;call context call back function.

_CancelEdit()

EndIf

;----------------------------------------------------------------------------------------------

If $DebugIt Then ConsoleWrite(_DebugHeader("$NM_RCLICK"))

;----------------------------------------------------------------------------------------------

EndFunc ;==>ListView_RClick

;===============================================================================

; Function Name: ListView_DoubleClick

; Description: Called from WN_NOTIFY event handler.

; Parameter(s):

; Requirement(s):

; Return Value(s):

; User CallTip:

; Author(s):

; Note(s): Initiates the edit process on a DblClick

;===============================================================================

Func _ListView_DoubleClick()

;----------------------------------------------------------------------------------------------

If $DebugIt Then ConsoleWrite(_DebugHeader("$NM_DBLCLICK"))

;----------------------------------------------------------------------------------------------

If $editFlag = 0 Then

_InitEdit($LVINFO, $LVcolControl)

Else

_CancelEdit($LVcolControl)

EndIf

EndFunc ;==>ListView_DoubleClick

; WM_NOTIFY event handler

;===============================================================================

; Function Name: _MonitorEditState

; Description: Handles {enter} {esc} and {f2}

; Parameter(s): $h_gui - IN/OUT -

; $editCtrl - IN/OUT -

; $editFlag - IN/OUT -

; $LISTVIEWCTRL - IN/OUT -

; $LVINFO - IN/OUT -

; $LVcolControl - IN -

; Requirement(s):

; Return Value(s):

; User CallTip:

; Author(s):

; Note(s):

;===============================================================================

Func _MonitorEditState(ByRef $h_gui, ByRef $editCtrl, ByRef $editFlag, ByRef $LISTVIEWCTRL, ByRef $LVINFO, $LVcolControl)

Local $pressed = _vKeyCheck()

If $editFlag And $pressed = 13 Then; pressed enter

_LVUpdate($editCtrl, $LISTVIEWCTRL, $LVINFO[0], $LVINFO[1])

ElseIf $editFlag And $pressed = 27 Then; pressed esc

_CancelEdit($LVcolControl)

$editFlag = 0

ElseIf Not $editFlag And $pressed = 113 Then; pressed f2

;;_InitEdit($LVINFO, $LVcolControl); hmmm, the control doesn't always focus correctly

MouseClick("primary") ;workaround work all the time (if mouse is over the control)

MouseClick("primary")

EndIf

If $editFlag and $pressed = 01 Then

If Not(_HasFocus($editCtrl)) Then

If $b_LVUpdateLOSTFOCUS Then _LVUpdate($editCtrl, $LISTVIEWCTRL, $LVINFO[0], $LVINFO[1])

EndIf

EndIf

EndFunc ;==>_MonitorEditState

Func Enter()

; just a dummy function

EndFunc ;==>Enter

;===============================================================================

; Function Name: _LVUpdate

; Description: Put the new data in the Listview

; Parameter(s): $editCtrl - IN/OUT -

; $LISTVIEWCTRL - IN/OUT -

; $iRow - IN -

; $iCol - IN -

;

; Requirement(s):

; Return Value(s):

; User CallTip:

; Author(s): $lvCheckBox by johnbailey don't get mad at Stephen Podhajecki, Gary Frost, or pdm for this addition sucking

; Note(s):

;===============================================================================

Func _LVUpdate(ByRef $editCtrl, ByRef $LISTVIEWCTRL, $iRow, $iCol)

If $editCtrl = $lvCheckbox Then

Local $CBstate = GUICtrlRead($editCtrl)

If $CBstate = 4 Then

Local $newText = ' ';chr(215)

ElseIf $CBstate = 1 THen

Local $newText = chr(149)

EndIf

Else

Local $newText = GUICtrlRead($editCtrl)

EndIf

Local $item = GUICtrlRead($LISTVIEWCTRL)

_GUICtrlListViewSetItemText($LISTVIEWCTRL, $iRow, $iCol, $newText)

_CancelEdit($LVcolControl)

If $EIP_ResetComboAfterClickDone Then

_GUICtrlComboResetContent ($lvCombo )

EndIf

EndFunc ;==>_LVUpdate

;===============================================================================

; Function Name: _GUICtrlListViewGetSubItemRect

; Description: Get the bounding rect of a listview item

; Parameter(s): $h_listview - IN -

; $row - IN -

; $col - IN -

; $aRect - IN/OUT -

;

; Requirement(s):

; Return Value(s):

; User CallTip:

; Author(s):

; Note(s):

;===============================================================================

Func _GUICtrlListViewGetSubItemRect($h_listview, $row, $col, ByRef $aRect)

Local $rectangle, $rv,$ht[4]

$rectangle = DllStructCreate("int;int;int;int") ;left, top, right, bottom

DllStructSetData($rectangle, 1, $LVIR_BOUNDS)

DllStructSetData($rectangle, 2, $col)

If IsHWnd($h_listview) Then

Local $a_ret = DllCall("user32.dll", "int", "SendMessage", "hwnd", $h_listview, "int", $LVM_GETSUBITEMRECT, "int", $row, "ptr", DllStructGetPtr($rectangle))

$rv = $a_ret[0]

Else

$rv = GUICtrlSendMsg($h_listview, $LVM_GETSUBITEMRECT, $row, DllStructGetPtr($rectangle))

EndIf

ReDim $aRect[4]

$aRect = $ht

$aRect[0] = DllStructGetData($rectangle, 1)

$aRect[1] = DllStructGetData($rectangle, 2)

$aRect[2] = DllStructGetData($rectangle, 3)

$aRect[3] = DllStructGetData($rectangle, 4) - $aRect[1]

$rectangle = 0

Sleep(10)

Return $rv

EndFunc ;==>_GUICtrlListViewGetSubItemRec

;===============================================================================

; Function Name: _InitEdit

; Description: Bring forth the editing control and set focus on it.

; Parameter(s): $LVINFO - IN -

; $LVcolControl - IN -

;

; Requirement(s):

; Return Value(s):

; User CallTip:

; Author(s):

; Note(s):

;===============================================================================

Func _InitEdit($LVINFO, $LVcolControl)

if $bCALLBACK Then

_CancelEdit($LVcolControl)

$bCALLBACK = False

EndIf

If $editFlag = 1 Then _CancelEdit($LVcolControl)

Local $CtrlType

If $LVINFO[0] < 0 Or $LVINFO[1] < 0 Then Return 0

If UBound($LVcolControl) - 1 < $LVINFO[1] Then

$CtrlType = 0

Else

$CtrlType = $LVcolControl[$LVINFO[1]]

EndIf

;----------------------------------------------------------------------------------------------

If $DebugIt Then ConsoleWrite(_DebugHeader("$CtrlType:" & $CtrlType))

;----------------------------------------------------------------------------------------------

Switch $CtrlType

Case 2

$editCtrl = $lvCombo

Case 4

$editCtrl = $lvDate

Case 1

GUICtrlSetData($lvEdit, "")

$editCtrl = $lvEdit

Case 256

$bCALLBACK= True

Case 128

$editCtrl = $lvCheckbox

Case Else

Return

EndSwitch

If $bCALLBACK Then

Call($LVCALLBACK,$LVINFO)

$bCALLBACK = False

Else

;----------------------------------------------------------------------------------------------

If $DebugIt Then ConsoleWrite(_DebugHeader("Classname="&_GetClassName($editCtrl)))

;----------------------------------------------------------------------------------------------

GUICtrlSetPos($editCtrl, $LVINFO[2], $LVINFO[3], $LVINFO[4], $LVINFO[5])

Local $oldText = _GUICtrlListViewGetItemText($LISTVIEWCTRL, $LVINFO[0], $LVINFO[1])

If $editCtrl = $lvCheckbox Then

If $oldText = chr(149) Then

GUICtrlSetState($editCtrl, $GUI_CHECKED)

Else

GUICtrlSetState($editCtrl, $GUI_UNCHECKED)

EndIf

Else

GUICtrlSetData($editCtrl, $oldText)

EndIf

GUICtrlSetState($editCtrl, $GUI_SHOW)

GUICtrlSetState($editCtrl, $GUI_FOCUS)

GUICtrlSetState($editCtrl, $GUI_ONTOP)

$editFlag = 1

EndIf

sleep(1000)

EndFunc ;==>_InitEdit

;===============================================================================

; Function Name: _CancelEdit

; Description: Cancels the editing process, and kills the hot keys.

; Parameter(s):

; Requirement(s):

; Return Value(s):

; User CallTip:

; Author(s):

; Note(s):

;===============================================================================

Func _CancelEdit($LVcolControl=0)

HotKeySet("{Enter}")

HotKeySet("{Esc}")

Send("{Enter}");quit edit mode

$editFlag = 0

$_LVUpdate = 0

if _GetClassName($editCtrl) = "Edit" Then GuiCtrlSetData($editCtrl,"")

GUICtrlSetState($editCtrl, $GUI_HIDE)

GUICtrlSetPos($editCtrl, 0, 0, 1, 1)

;----------------------------------------------------------------------------------------------

If $DebugIt Then ConsoleWrite(_DebugHeader("_CancelEdit()"))

;----------------------------------------------------------------------------------------------

EndFunc ;==>_CancelEdit

;===============================================================================

; Function Name: _FillLV_Info

; Description: This fills the passed in array with row col and rect info for

; used by the editing controls

; Parameter(s): $LISTVIEWCTRL - IN/OUT -

; $iRow - IN -

; $iCol - IN -

; $aLVI - IN/OUT -

;

; Requirement(s):

; Return Value(s):

; User CallTip:

; Author(s):

; Note(s):

;===============================================================================

Func _FillLV_Info(ByRef $LISTVIEWCTRL, $iRow, $iCol, ByRef $aLVI)

$aLVI[6] = $aLVI[0] ;set old row

$aLVI[7] = $aLVI[1] ;set old col

$aLVI[0] = $iRow ;set new row

$aLVI[1] = $iCol ;set new col

If $iRow < 0 Or $iCol < 0 Then Return 0

Local $lvi_rect[4], $ret, $pos = ControlGetPos("", "", $LISTVIEWCTRL)

$ret = _GUICtrlListViewGetSubItemRect($LISTVIEWCTRL, $iRow, $iCol, $lvi_rect)

$aLVI[2] = $pos[0] + $lvi_rect[0] + 5

$aLVI[3] = $pos[1] + $lvi_rect[1]

$aLVI[4] = _GUICtrlListViewGetColumnWidth($LISTVIEWCTRL, $iCol) - 4

$aLVI[5] = $lvi_rect[3] + 5

Sleep(10)

Return 1

EndFunc ;==>_FillLV_Info

;===============================================================================

; Function Name: WM_Notify_Events_EditInPlaceStandard

; Description: Event handler for windows WN_NOTIFY messages

; Parameter(s): $hWndGUI - IN -

; $MsgID - IN -

; $wParam - IN -

; $lParam - IN -

;

; Requirement(s):

; Return Value(s):

; User CallTip:

; Author(s):

; Note(s):

;===============================================================================

Func WM_Notify_Events_EditInPlaceStandard($hWndGUI, $MsgID, $wParam, $lParam)

#forceref $hWndGUI, $MsgID, $wParam

Local $tagNMHDR, $event, $from

$tagNMHDR = DllStructCreate("int;int;int", $lParam);NMHDR (hwndFrom, idFrom, code)

If @error Then

$tagNMHDR =0

Return

EndIf

$from = DllStructGetData($tagNMHDR, 1)

$event = DllStructGetData($tagNMHDR, 3)

;$tagNMHDR = 0

Select

Case $wParam = $LISTVIEWCTRL

Select

Case $event = $NM_CLICK

_LVGetInfo_Standard($lParam)

_ListView_Click()

Case $event = $NM_DBLCLK

_LVGetInfo_Standard($lParam)

_ListView_DoubleClick()

Case $event = $NM_RCLICK

_LVGetInfo_Standard($lParam)

_ListView_RClick()

Case Else

Select

Case $event = $NM_CLICK

Send("{ESC}")

_ListView_Click()

Case $event = $NM_DBLCLK

Send("{ESC}")

_ListView_Click()

Case - 121

_LVGetInfo_Standard($lParam,1)

EndSelect

EndSelect

Case $MsgID = $WM_KEYDOWN

;----------------------------------------------------------------------------------------------

If $DebugIt Then ConsoleWrite(_DebugHeader("Keydown"))

;----------------------------------------------------------------------------------------------

Case Else

;;uncomment the following line to have the edit _LVUpdate if the mouse moves

;;off of the listview.

;;If $editFlag And Not(_HasFocus($editCtrl)) Then _LVUpdate($editCtrl, $LISTVIEWCTRL, $LVINFO[0], $LVINFO[1])

EndSelect

$tagNMHDR = 0

$event = 0

$lParam = 0

;Return $GUI_RUNDEFMSG

EndFunc ;==>WM_Notify_Events_EditInPlaceStandard

Func _LVGetInfo_Standard($lParam,$iFlag =0 )

$tagNMITEMACTIVATE_EIP = DllStructCreate("int;int;int;int;int;int;int;int;int", $lParam)

$clicked_row = DllStructGetData($tagNMITEMACTIVATE_EIP, 4)

$clicked_col = DllStructGetData($tagNMITEMACTIVATE_EIP, 5)

if $clicked_col < -1 then $clicked_col = -1

if $clicked_row < -1 then $clicked_row = -1

if $clicked_col > _GUICtrlListViewGetSubItemsCount($LISTVIEWCTRL) then $clicked_col = -1

if $clicked_row > _GUICtrlListViewGetItemCount($LISTVIEWCTRL) then $clicked_row = -1

$tagNMITEMACTIVATE_EIP = 0

if $iFlag =0 then

_FillLV_Info($LISTVIEWCTRL, $clicked_row, $clicked_col, $LVINFO)

$old_col = $clicked_col

EndIf

$LVINFO[8] = $clicked_row

$LVINFO[9] = $clicked_col

;----------------------------------------------------------------------------------------------

If $DebugIt Then ConsoleWrite(_DebugHeader("Col:" & $clicked_col))

If $DebugIt Then ConsoleWrite(_DebugHeader("Row:" & $clicked_row))

;----------------------------------------------------------------------------------------------

EndFunc

;===============================================================================

; Function Name: _DebugHeader

; Description: Gary's console debug header.

; Parameter(s): $s_text - IN -

;

; Requirement(s):

; Return Value(s):

; User CallTip:

; Author(s):

; Note(s):

;===============================================================================

Func _DebugHeader($s_text)

Return _

"!===========================================================" & @LF & _

"+===========================================================" & @LF & _

"-->" & $s_text & @LF & _

"+===========================================================" & @LF

EndFunc ;==>_DebugHeader

;===============================================================================

; Function Name: _GetClassName

; Description: get the classname of a ctrl

; Parameter(s): $nCtrl the ctrlId of to get classname for.

; Requirement(s):

; Return Value(s): Classname or 0 on failure

; User CallTip:

; Author(s): Stephen Podhajecki <gehossafats at netmdc.com/>

; Note(s): Strips trailing numbers from classname.

;===============================================================================

Func _GetClassName($nCtrl)

Local $struct = DllStructCreate("char[128]"),$classname = 0

$ret = DllCall("user32.dll","int","GetClassName","hwnd",GUICtrlGetHandle($nCtrl),"ptr",DllStructGetPtr($struct),"int",DllStructGetSize($struct))

If IsArray($ret) Then

$classname = DllStructGetData($struct,1)

While (StringIsDigit(StringRight($classname,1)))

$classname = StringTrimRight($classname,1)

WEnd

EndIf

$struct =0

Return $classname

EndFunc

;===============================================================================

; Function Name: vKeyCheck alias for __IsPressedMod

; Description: Gets a key press

; Parameter(s): $dll - IN/OPTIONAL -

; Requirement(s):

; Return Value(s): Return the key that is pressed or 0

; User CallTip:

; Author(s):

; Note(s):

;===============================================================================

Func _vKeyCheck($dll = "user32.dll")

Local $aR, $bRv, $hexKey, $i

Local $vkeys[4]=[1,13,27,113];leftmouse,enter,esc,f2

For $i =0 to UBound($vkeys)-1

$hexKey = '0x'&Hex($vkeys[$i],2)

$aR = DllCall($dll, "int", "GetAsyncKeyState", "int", $hexKey)

If $aR[0] <> 0 Then Return $vkeys[$i]

Sleep(5)

Next

Return 0

EndFunc ;==>__IsPressedMod

;===============================================================================

; Function Name : _HasFocus

; Description : Return true if control has focus

; Parameter(s) : $nCtrl Ctrlid to check

; Return Value(s) : True is ctrl has focus, false otherwise.

; User CallTip :

; Author(s) : Stephen Podhajecki <gehossafats at netmdc.com/>

; Note(s) :

;===============================================================================

Func _HasFocus($nCtrl)

Return (BitAND(GUICtrlGetState($nCtrl),256) = 256)

EndFunc

Func _SetLVCallBack($CallBack = "_CancelEdit")

If $CallBack <> "" Then $LVCALLBACK = $CallBack

EndFunc

Func _SetLVContext($Context = "_CancelEdit")

if $Context <> "" Then $LVCONTEXT = $Context

EndFunc

;;;ripped from help file.

; Convert the client (GUI) coordinates to screen (desktop) coordinates

Func ClientToScreen($hWnd, ByRef $x, ByRef $y)

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

DllStructSetData($stPoint, 1, $x)

DllStructSetData($stPoint, 2, $y)

DllCall("user32.dll", "int", "ClientToScreen", "hwnd", $hWnd, "ptr", DllStructGetPtr($stPoint))

$x = DllStructGetData($stPoint, 1)

$y = DllStructGetData($stPoint, 2)

; release Struct not really needed as it is a local

$stPoint = 0

EndFunc

; added TPM_RETURNCMD to uflags to get menu item return value.

; Show at the given coordinates (x, y) the popup menu (hMenu) which belongs to a given GUI window (hWnd)

Func TrackPopupMenu($hWnd, $hMenu, $x, $y)

Local $v_ret = DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hMenu, "int",0X100, "int", $x, "int", $y, "hwnd", $hWnd, "ptr", 0)

Return $v_ret[0]

EndFunc

A decision is a powerful thing
Link to comment
Share on other sites

Gosh the updates ROCK!!!!!!!

Now I got to fix my scripts using this udf ( I had a lot of crappy "patch" work I tried )

Edit:

Bug report: Right-click popup gui does not go to the mouse's location.

Edited by JohnBailey
A decision is a powerful thing
Link to comment
Share on other sites

Bug report: Right-click popup gui does not go to the mouse's location.

Fixed.

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