Sign in to follow this  
Followers 0
Nithyanandam

How to set Highlight mark on a listview item.

6 posts in this topic

#1 ·  Posted (edited)

In Listview, Selected Item has the Highlighed mark in blue. When i press the UP button, this button makes the selected item to go UP by one position. and same for DOWN button.

Now the issue is I am not able to set the highlighted mark to the item which is gone UP by one position, and the higlight is lost when the UP or Down Button is pressed.

Please check the Attachement.

As of now the Hightlighted mark is set as per my select which is in the last Item > OC Lexus_Nexus.

post-50561-12541141371378_thumb.png

Edited by Nithyanandam

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hi,

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

Global $hGui, $iLV, $iDown, $iUp, $Msg

$hGui = GUICreate(":-)", 600, 300)
$iLV = GUICtrlCreateListView("Application|Area|Enviroment|Iterations|Execute By", 5, 5, 500, 290)
GUICtrlCreateListViewItem("AWB|STM|UAT|10|Sasikumar", $iLV)
GUICtrlCreateListViewItem("CC|ARAD|UAT|10|Sasikumar", $iLV)
GUICtrlCreateListViewItem("OC|LEXUS_NEXUS|UAT|10|Sasikumar", $iLV)
GUICtrlCreateListViewItem("PP|LB|UAT|10|Sasikumar", $iLV)
$iUp = GUICtrlCreateButton("Move Up", 510, 120, 85, 25)
$iDown = GUICtrlCreateButton("Move Down", 510, 155, 85, 25)
GUISetState(@SW_SHOW, $hGui)

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $iUp
            _MoveUp()
        Case $iDown
            _MoveDown()
    EndSwitch
WEnd

Func _MoveUp()
    Local $iCur, $iPrev, $sCur, $sPrev
    $iCur = _GUICtrlListView_GetNextItem($iLV)
    If $iCur > 0 Then
        $iPrev = $iCur - 1
        $sCur = _GUICtrlListView_GetItemTextString($iLV, $iCur)
        $sPrev = _GUICtrlListView_GetItemTextString($iLV, $iPrev)
        GUICtrlSetData(_GUICtrlListView_GetItemParam($iLV, $iCur), $sPrev)
        GUICtrlSetData(_GUICtrlListView_GetItemParam($iLV, $iPrev), $sCur)
        _GUICtrlListView_SetItemSelected($iLV, $iCur, False)
        _GUICtrlListView_SetItemSelected($iLV, $iPrev)
    EndIf
EndFunc   ;==>_MoveUp

Func _MoveDown()
    Local $iCur, $iNext, $sCur, $sNext
    $iCur = _GUICtrlListView_GetNextItem($iLV)
    If $iCur < _GUICtrlListView_GetItemCount($iLV) - 1 And $iCur <> -1 Then
        $iNext = $iCur + 1
        $sCur = _GUICtrlListView_GetItemTextString($iLV, $iCur)
        $sNext = _GUICtrlListView_GetItemTextString($iLV, $iNext)
        GUICtrlSetData(_GUICtrlListView_GetItemParam($iLV, $iCur), $sNext)
        GUICtrlSetData(_GUICtrlListView_GetItemParam($iLV, $iNext), $sCur)
        _GUICtrlListView_SetItemSelected($iLV, $iCur, False)
        _GUICtrlListView_SetItemSelected($iLV, $iNext)
    EndIf
EndFunc   ;==>_MoveDown

Cheers

PS. it would have been easier to help if you'd post some code instead of the pretty picture :D

Edited by smashly

Share this post


Link to post
Share on other sites

Hi,

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

Global $hGui, $iLV, $iDown, $iUp, $Msg

$hGui = GUICreate(":-)", 600, 300)
$iLV = GUICtrlCreateListView("Application|Area|Enviroment|Iterations|Execute By", 5, 5, 500, 290)
GUICtrlCreateListViewItem("AWB|STM|UAT|10|Sasikumar", $iLV)
GUICtrlCreateListViewItem("CC|ARAD|UAT|10|Sasikumar", $iLV)
GUICtrlCreateListViewItem("OC|LEXUS_NEXUS|UAT|10|Sasikumar", $iLV)
GUICtrlCreateListViewItem("PP|LB|UAT|10|Sasikumar", $iLV)
$iUp = GUICtrlCreateButton("Move Up", 510, 120, 85, 25)
$iDown = GUICtrlCreateButton("Move Down", 510, 155, 85, 25)
GUISetState(@SW_SHOW, $hGui)

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $iUp
            _MoveUp()
        Case $iDown
            _MoveDown()
    EndSwitch
WEnd

Func _MoveUp()
    Local $iCur, $iPrev, $sCur, $sPrev
    $iCur = _GUICtrlListView_GetNextItem($iLV)
    If $iCur > 0 Then
        $iPrev = $iCur - 1
        $sCur = _GUICtrlListView_GetItemTextString($iLV, $iCur)
        $sPrev = _GUICtrlListView_GetItemTextString($iLV, $iPrev)
        GUICtrlSetData(_GUICtrlListView_GetItemParam($iLV, $iCur), $sPrev)
        GUICtrlSetData(_GUICtrlListView_GetItemParam($iLV, $iPrev), $sCur)
        _GUICtrlListView_SetItemSelected($iLV, $iCur, False)
        _GUICtrlListView_SetItemSelected($iLV, $iPrev)
    EndIf
EndFunc   ;==>_MoveUp

Func _MoveDown()
    Local $iCur, $iNext, $sCur, $sNext
    $iCur = _GUICtrlListView_GetNextItem($iLV)
    If $iCur < _GUICtrlListView_GetItemCount($iLV) - 1 And $iCur <> -1 Then
        $iNext = $iCur + 1
        $sCur = _GUICtrlListView_GetItemTextString($iLV, $iCur)
        $sNext = _GUICtrlListView_GetItemTextString($iLV, $iNext)
        GUICtrlSetData(_GUICtrlListView_GetItemParam($iLV, $iCur), $sNext)
        GUICtrlSetData(_GUICtrlListView_GetItemParam($iLV, $iNext), $sCur)
        _GUICtrlListView_SetItemSelected($iLV, $iCur, False)
        _GUICtrlListView_SetItemSelected($iLV, $iNext)
    EndIf
EndFunc   ;==>_MoveDown

Cheers

PS. it would have been easier to help if you'd post some code instead of the pretty picture :D

Share this post


Link to post
Share on other sites

Hi I have used these two functions. Though this is a leangthy approach, please check itout and let me know where I was wrong.

; #FUNCTION# ===================================================================
; Name ..........:
; Description ...:
; ==============================================================================
Func btnMoveScriptsUp()
    If _GUICtrlListView_GetSelectedCount($hListViewScriptsSelectedToRun) = 1 Then
        Local $SelectRowToMoveUp, $AppToRunUP, $AreaToRunUP, $EnvToRunUP, $IteraToRunUP, $ExecByToRunUP
        Local $AppToRunDown, $AreaToRunDown, $EnvToRunDown, $IteraToRunDown, $ExecByToRunDown
        $SelectRowToMoveUp = _GUICtrlListView_GetSelectedIndices($hListViewScriptsSelectedToRun)
        If $SelectRowToMoveUp > 0 Then
;~          MsgBox(0, "$SelectRowToMoveUp", $SelectRowToMoveUp)
            $AppToRunUP = _GUICtrlListView_GetItemText($hListViewScriptsSelectedToRun, Int($SelectRowToMoveUp), 0)
            $AreaToRunUP = _GUICtrlListView_GetItemText($hListViewScriptsSelectedToRun, Int($SelectRowToMoveUp), 1)
            $EnvToRunUP = _GUICtrlListView_GetItemText($hListViewScriptsSelectedToRun, Int($SelectRowToMoveUp), 2)
            $IteraToRunUP = _GUICtrlListView_GetItemText($hListViewScriptsSelectedToRun, Int($SelectRowToMoveUp), 3)
            $ExecByToRunUP = _GUICtrlListView_GetItemText($hListViewScriptsSelectedToRun, Int($SelectRowToMoveUp), 4)

            $AppToRunDown = _GUICtrlListView_GetItemText($hListViewScriptsSelectedToRun, Int($SelectRowToMoveUp - 1), 0)
            $AreaToRunDown = _GUICtrlListView_GetItemText($hListViewScriptsSelectedToRun, Int($SelectRowToMoveUp - 1), 1)
            $EnvToRunDown = _GUICtrlListView_GetItemText($hListViewScriptsSelectedToRun, Int($SelectRowToMoveUp - 1), 2)
            $IteraToRunDown = _GUICtrlListView_GetItemText($hListViewScriptsSelectedToRun, Int($SelectRowToMoveUp - 1), 3)
            $ExecByToRunDown = _GUICtrlListView_GetItemText($hListViewScriptsSelectedToRun, Int($SelectRowToMoveUp - 1), 4)

            _GUICtrlListView_SetItem($hListViewScriptsSelectedToRun, $AppToRunUP, ($SelectRowToMoveUp - 1))
            _GUICtrlListView_SetItem($hListViewScriptsSelectedToRun, $AreaToRunUP, ($SelectRowToMoveUp - 1), 1)
            _GUICtrlListView_SetItem($hListViewScriptsSelectedToRun, $EnvToRunUP, ($SelectRowToMoveUp - 1), 2)
            _GUICtrlListView_SetItem($hListViewScriptsSelectedToRun, $IteraToRunUP, ($SelectRowToMoveUp - 1), 3)
            _GUICtrlListView_SetItem($hListViewScriptsSelectedToRun, $ExecByToRunUP, ($SelectRowToMoveUp - 1), 4)

            _GUICtrlListView_SetItem($hListViewScriptsSelectedToRun, $AppToRunDown, $SelectRowToMoveUp)
            _GUICtrlListView_SetItem($hListViewScriptsSelectedToRun, $AreaToRunDown, $SelectRowToMoveUp, 1)
            _GUICtrlListView_SetItem($hListViewScriptsSelectedToRun, $EnvToRunDown, $SelectRowToMoveUp, 2)
            _GUICtrlListView_SetItem($hListViewScriptsSelectedToRun, $IteraToRunDown, $SelectRowToMoveUp, 3)
            _GUICtrlListView_SetItem($hListViewScriptsSelectedToRun, $ExecByToRunDown, $SelectRowToMoveUp, 4)

;~          _GUICtrlListView_SetSelectionMark($hListViewScriptsSelectedToRun, ($SelectRowToMoveUp - 1))
;~          _GUICtrlListView_SetItemState($hListViewScriptsSelectedToRun, ($SelectRowToMoveUp - 1), $LVIS_SELECTED, $LVIS_SELECTED)
;~          _GUICtrlListView_SetItemState($hListViewScriptsSelectedToRun, ($SelectRowToMoveUp - 1), $LVIS_DROPHILITED, $LVIS_DROPHILITED)
            _GUICtrlListView_SetItemSelected($hListViewScriptsSelectedToRun, ($SelectRowToMoveUp - 1), True, True)
;~          _GUICtrlListView_SetCallBackMask($hListViewScriptsSelectedToRun, 8)



        EndIf
    Else
        MsgBox(64, "Error", "Please Select one script")
    EndIf
EndFunc   ;==>btnMoveScriptsUp

; #FUNCTION# ===================================================================
; Name ..........:
; Description ...:
; ==============================================================================
Func btnMoveScriptsDown()
    If _GUICtrlListView_GetSelectedCount($hListViewScriptsSelectedToRun) = 1 Then
        Local $SelectRowToMoveUp, $AppToRunUP, $AreaToRunUP, $EnvToRunUP, $IteraToRunUP, $ExecByToRunUP
        Local $AppToRunDown, $AreaToRunDown, $EnvToRunDown, $IteraToRunDown, $ExecByToRunDown
        $SelectRowToMoveUp = _GUICtrlListView_GetSelectedIndices($hListViewScriptsSelectedToRun)
;~      MsgBox(0, $SelectRowToMoveUp, _GUICtrlListView_GetItemCount($hListViewScriptsSelectedToRun))
        If $SelectRowToMoveUp <> _GUICtrlListView_GetItemCount($hListViewScriptsSelectedToRun) - 1 Then
;~          MsgBox(0, "$SelectRowToMoveUp", $SelectRowToMoveUp)
            $AppToRunUP = _GUICtrlListView_GetItemText($hListViewScriptsSelectedToRun, Int($SelectRowToMoveUp + 1), 0)
            $AreaToRunUP = _GUICtrlListView_GetItemText($hListViewScriptsSelectedToRun, Int($SelectRowToMoveUp + 1), 1)
            $EnvToRunUP = _GUICtrlListView_GetItemText($hListViewScriptsSelectedToRun, Int($SelectRowToMoveUp + 1), 2)
            $IteraToRunUP = _GUICtrlListView_GetItemText($hListViewScriptsSelectedToRun, Int($SelectRowToMoveUp + 1), 3)
            $ExecByToRunUP = _GUICtrlListView_GetItemText($hListViewScriptsSelectedToRun, Int($SelectRowToMoveUp + 1), 4)

            $AppToRunDown = _GUICtrlListView_GetItemText($hListViewScriptsSelectedToRun, Int($SelectRowToMoveUp), 0)
            $AreaToRunDown = _GUICtrlListView_GetItemText($hListViewScriptsSelectedToRun, Int($SelectRowToMoveUp), 1)
            $EnvToRunDown = _GUICtrlListView_GetItemText($hListViewScriptsSelectedToRun, Int($SelectRowToMoveUp), 2)
            $IteraToRunDown = _GUICtrlListView_GetItemText($hListViewScriptsSelectedToRun, Int($SelectRowToMoveUp), 3)
            $ExecByToRunDown = _GUICtrlListView_GetItemText($hListViewScriptsSelectedToRun, Int($SelectRowToMoveUp), 4)

            _GUICtrlListView_SetItem($hListViewScriptsSelectedToRun, $AppToRunUP, ($SelectRowToMoveUp))
            _GUICtrlListView_SetItem($hListViewScriptsSelectedToRun, $AreaToRunUP, ($SelectRowToMoveUp), 1)
            _GUICtrlListView_SetItem($hListViewScriptsSelectedToRun, $EnvToRunUP, ($SelectRowToMoveUp), 2)
            _GUICtrlListView_SetItem($hListViewScriptsSelectedToRun, $IteraToRunUP, ($SelectRowToMoveUp), 3)
            _GUICtrlListView_SetItem($hListViewScriptsSelectedToRun, $ExecByToRunUP, ($SelectRowToMoveUp), 4)

            _GUICtrlListView_SetItem($hListViewScriptsSelectedToRun, $AppToRunDown, $SelectRowToMoveUp + 1)
            _GUICtrlListView_SetItem($hListViewScriptsSelectedToRun, $AreaToRunDown, ($SelectRowToMoveUp + 1), 1)
            _GUICtrlListView_SetItem($hListViewScriptsSelectedToRun, $EnvToRunDown, ($SelectRowToMoveUp + 1), 2)
            _GUICtrlListView_SetItem($hListViewScriptsSelectedToRun, $IteraToRunDown, ($SelectRowToMoveUp + 1), 3)
            _GUICtrlListView_SetItem($hListViewScriptsSelectedToRun, $ExecByToRunDown, ($SelectRowToMoveUp + 1), 4)

;~          _GUICtrlListView_SetSelectionMark($hListViewScriptsSelectedToRun, ($SelectRowToMoveUp + 1))
;~          _GUICtrlListView_SetItemState($hListViewScriptsSelectedToRun, ($SelectRowToMoveUp + 1), $LVIS_SELECTED, $LVIS_SELECTED)
;~          _GUICtrlListView_SetItemState($hListViewScriptsSelectedToRun, ($SelectRowToMoveUp + 1), $LVIS_DROPHILITED, $LVIS_DROPHILITED)
            _GUICtrlListView_SetItemSelected($hListViewScriptsSelectedToRun, ($SelectRowToMoveUp + 1), True, True)
;~          _GUICtrlListView_SetCallBackMask($hListViewScriptsSelectedToRun, 8)




        EndIf
    Else
        MsgBox(64, "Error", "Please Select one script")
    EndIf
EndFunc   ;==>btnMoveScriptsDown

Share this post


Link to post
Share on other sites

And thanks for your reply. :-)

Share this post


Link to post
Share on other sites

And thanks for your reply. :-)

Hi and your welcome,

For me to even approach looking at where it's going wrong you would need to provide a snippet of working code..

eg: code I can paste into scite editor and actually run.

As it is I'm having to guess things that are in your snippet you supplied.

eg: I wonder if he's using AutoIt's built in GUICtrlCreateListView() or the external UDF _GUICtrlListView_Create()..

or

I gather he's using _GUICtrlListView_AddItem() or is he using GUICtrlCreateListViewItem()..

To save me having to fill in blanks please supply a working snippet of code so I don't have to guess or write a whole script just to debug your snippet.

Cheers

Share this post


Link to post
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
Sign in to follow this  
Followers 0