Jump to content

Recommended Posts

Posted

Hello,

I have a listview with 3 items and I have to change background color from first to last with a sleep of one second between them.

How to do that if the items are not called? they are dynamic.

 

*I know how to change the background color of the item, just how to use For , To , Next in order to identify them from the first to the last one.

 

Thank you , sry for my bad english.

Posted
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>

Global $value = 3

$Form1 = GUICreate("Form1", 605, 331, -1, -1)
$ListView1 = GUICtrlCreateListView("#|Example", 0, 0, 602, 262)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 150)
$Button1 = GUICtrlCreateButton("create", 16, 280, 75, 25)
$Button2 = GUICtrlCreateButton("go", 116, 280, 75, 25)

GUISetState(@SW_SHOW, $Form1)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Button1
            For $i = 1 To $value
                GUICtrlCreateListViewItem("item" & $i & "|" & "example", $ListView1)
            Next

        Case $Button2
            For $i = 0 To _GUICtrlListView_GetItemCount($ListView1)
                Sleep(1000)
                ;change for every item background color
            Next

    EndSwitch
WEnd

Hello,

Thank you for your help!

 

When you click $Button1 it creates how many listview items I want.

When the user click $Button2 I want to wait one second and change background to all items until it reach the last one.

Posted (edited)

@Slipk
One of many ways :)

#include <ButtonConstants.au3>
#include <ColorConstants.au3> ; Added
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>

Global $value = 3, _
       $arrItemIDs[$value], _ ; Added
       $intItemColor          ; Added

$Form1 = GUICreate("Form1", 605, 331, -1, -1)
$ListView1 = GUICtrlCreateListView("#|Example", 0, 0, 602, 262)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 150)
$Button1 = GUICtrlCreateButton("create", 16, 280, 75, 25)
$Button2 = GUICtrlCreateButton("go", 116, 280, 75, 25)

GUISetState(@SW_SHOW, $Form1)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Button1
            For $i = 0 To $value - 1 ; Changed $i from 1 to 0
               $arrItemIDs[$i] = GUICtrlCreateListViewItem("item" & $i & "|" & "example", $ListView1) ; Added
            Next

        Case $Button2

            ; Added
            For $i = 0 To UBound($arrItemIDs) - 1 Step 1
                ; Sleep(1000)
                ;change for every item background color
                If Mod($i, 2) = 0 Then
                    $intItemColor = $COLOR_YELLOW
                Else
                    $intItemColor = $COLOR_SILVER
                EndIf

                GUICtrlSetBkColor($arrItemIDs[$i], $intItemColor)
            Next

    EndSwitch
WEnd

 

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...