Jump to content

GuiListView Color single Column


 Share

Recommended Posts

  • Moderators

PINTO1927,

Take a look at my GUIListViewEx UDF (the link is in my sig).

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

Thanks.

I'm getting data by SQL query. I want to colour a specific item by its content. Now i've create a cycle to check every items in the array. If this check reporting true, than i want to use setcolour function to edit item bg colour:

_GUICtrlListView_AddArray($lista, $filtro_ok)
_GUICtrlListView_DeleteItem($lista, 0)
$lista_int = _GUIListViewEx_Init($lista, $filtro_ok, 1, "", True, 1 + 2 + 4 + 8   + 16  + 32  + 64  + 128 + 256 + 512 + 1024)
Global $i
ConsoleWrite($filtro_ok[2][2])
For $i = 1 to UBound($filtro_ok)
   If $filtro_ok[$i-1][2] = "Altro" Then
      _GUIListViewEx_SetColour($lista, "0xFF0000;", $i, 2)
   EndIf
   Next


GUISetState(@SW_SHOW, $hGUI)

Here variables legend:

$lista = listview

$filtro_ok = array

"Altro" = the constant for the format condition

Thank you again.

Edited by PINTO1927
Link to comment
Share on other sites

  • Moderators

Pinto1927,

just one or two things!

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

#include "GUIListViewEx.au3"

Global $iLine = 1

$hGUI = GUICreate("Test", 500, 500)

$lista = GUICtrlCreateListView("Data 0|Data 1|Data 2", 10, 10, 480, 420, BitOR($LVS_SINGLESEL, $LVS_SHOWSELALWAYS))

GUICtrlCreateListViewItem("Item 0-0|Item 0-1|Item 0-2", $lista)

$cButton = GUICtrlCreateButton("Add item", 10, 450, 80, 30)

$aLista_Array = _GUIListViewEx_ReadToArray($lista)

$lista_int = _GUIListViewEx_Init($lista, $aLista_Array, 0, 0, True, 1 + 8 + 32)

; Set column 1 editable
_GUIListViewEx_SetEditStatus($lista_int, 1)
; Create colour array for exisiting data...
Global $aLista_Col[1][3] = [["", ";0xFFFF00", ""]]
; ...and load colours
_GUIListViewEx_LoadColour($lista_int, $aLista_Col)

; Important to do this before showing the GUI when using colour
_GUIListViewEx_MsgRegister()

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cButton
            ; Insert a new line
            _GUIListViewEx_Insert("Item " & $iLine & "-0|Item " & $iLine & "-1|Item " & $iLine & "-2")
            ; And set the colour for the new line
            _GUIListViewEx_SetColour($lista_int, ";0xFFFF00", 0, 1)
            ; Increase lne count
            $iLine += 1

    EndSwitch

    _GUIListViewEx_EventMonitor()

WEnd

Clearer now?

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

Perfect, thank you,

I managed to change one color at a single column based on content. latest problem, after the second time riesego the script to update data in the listview appears this message:

"C:\Program Files (x86)\AutoIt3\Include\GUIListViewEx.au3" (3339) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
If StringInStr(($aGLVEx_Data[0][13])[$iItem + 1][$iSubItem], ";") Then
If StringInStr(($aGLVEx_Data[0][13]^ ERROR

 

Link to comment
Share on other sites

  • Moderators

PINTO1927,

At a guess you are adding data to the ListView using normal AutoIt functions rather then via the UDF - as a result the UDF believes the content to be different to the actual content. I can inly suggest posting the entire script so that I can take a look and see what is going on inside the UDF.

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

 

Certainly, thanks:

#include <File.au3>
#include <Misc.au3>
#include <String.au3>
#include <Array.au3>
#include <_sql.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <DateTimeConstants.au3>


#include "GUIListViewEx.au3"

   Local $ServerAddress = "192.168.1.206"
   Local $ServerUserName = "username"
   Local $ServerPassword = "password"
   Local $DatabaseName = "INTEGRATION"

   _SQL_RegisterErrorHandler()
   $OADODB = _SQL_Startup()
   If $OADODB = $SQL_ERROR Then MsgBox(0 + 16 + 262144, "Error", _SQL_GetErrMsg())
   If _sql_Connect(-1, $ServerAddress, $DatabaseName, $ServerUserName, $ServerPassword) = $SQL_ERROR Then
      MsgBox(0 + 16 + 262144, "Error 1", _SQL_GetErrMsg())
      _SQL_Close()
      Exit
   EndIf

Global $gui_bo = GUICreate("database.integration", 1100, 720, -1, -1)

$lista = _GUICtrlListView_Create($gui_bo,"test|test|test|test|test|test|test|test|test|test|test", 10, 10, 900, 450, BitOr($LVS_REPORT, $LVS_SINGLESEL, $LVS_SHOWSELALWAYS))

GUICtrlCreateLabel("filter date :", 920, 30, 110, 22)
$filtro_data = GUICtrlCreateDate("", 920, 50, 170, 22, $DTS_SHORTDATEFORMAT)
GUICtrlSetFont(-1, 11, 400, 2, "Calibri")
Local $sStyle = "yyyy-MM-dd"
GUICtrlSendMsg($filtro_data, $DTM_SETFORMATW, 0, $sStyle)

GUICtrlCreateLabel("filter date:", 920, 80, 110, 22)
$filtro_data2 = GUICtrlCreateDate("", 920, 100, 170, 22, $DTS_SHORTDATEFORMAT)
GUICtrlSetFont(-1, 11, 400, 2, "Calibri")
Local $sStyle2 = "yyyy-MM-dd"
GUICtrlSendMsg($filtro_data2, $DTM_SETFORMATW, 0, $sStyle2)

$applica_filtro = GUICtrlCreateButton("&cerca", 920, 430, 75, 40)
GUICtrlSetFont(-1, 11, 800, 2, "Calibri")
GUICtrlSetImage(-1, "shell32.dll",23)

_GUIListViewEx_MsgRegister()

GUISetState(@SW_SHOW, $gui_bo)

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

      Local $filtro_ok = 0, $colonna_filtro = '', $riga_filtro = ''
      _sql_gettable2d(-1, "exec filtrobo'','','','"&Guictrlread($filtro_data)&"','"&Guictrlread($filtro_data2)&"','','',''", $filtro_ok, $riga_filtro, $colonna_filtro)
      _GUICtrlListView_AddArray($lista, $filtro_ok)


      $aLista_Array = _GUIListViewEx_ReadToArray($lista)
      $lista_int = _GUIListViewEx_Init($lista, $aLista_Array, 0, 0, True, 1 + 8 + 32)
      _GUIListViewEx_SetEditStatus($lista_int, 1)

      For $i = 1 to UBound($filtro_ok) - 1
         If $filtro_ok[$i][4] = "IN LAVORAZIONE" Then
            _GUIListViewEx_SetColour($lista_int, "0xFF0000;", $i-1, 4)
         ElseIf $filtro_ok[$i][4] = "RECLAMO CHIUSO" Then
            _GUIListViewEx_SetColour($lista_int, "0x009900;", $i-1, 4)
         ElseIf $filtro_ok[$i][4] = "RECLAMO DA GESTIRE BO" Then
            _GUIListViewEx_SetColour($lista_int, "0x0000FF;", $i-1, 4)
         EndIf
      Next

   EndSwitch
WEnd

 

the variable $applica_filtro run a query for the date and returns the result in me listview.

Link to comment
Share on other sites

  • Moderators

PINTO1927,

With a few small changes it works for me:

#include <File.au3>
#include <Misc.au3>
#include <String.au3>
#include <Array.au3>
;#include <_sql.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <DateTimeConstants.au3>


#include "GUIListViewEx.au3"

Local $ServerAddress = "192.168.1.206"
Local $ServerUserName = "username"
Local $ServerPassword = "password"
Local $DatabaseName = "INTEGRATION"

;_SQL_RegisterErrorHandler()
;$OADODB = _SQL_Startup()
;If $OADODB = $SQL_ERROR Then MsgBox(0 + 16 + 262144, "Error", _SQL_GetErrMsg())
;If _sql_Connect(-1, $ServerAddress, $DatabaseName, $ServerUserName, $ServerPassword) = $SQL_ERROR Then
;   MsgBox(0 + 16 + 262144, "Error 1", _SQL_GetErrMsg())
;   _SQL_Close()
;   Exit
;EndIf

Global $gui_bo = GUICreate("database.integration", 1100, 720, -1, -1)

$lista = _GUICtrlListView_Create($gui_bo, "test|test|test|test|test|test|test|test|test|test|test", 10, 10, 900, 450, BitOR($LVS_REPORT, $LVS_SINGLESEL, $LVS_SHOWSELALWAYS))

GUICtrlCreateLabel("filter date :", 920, 30, 110, 22)
$filtro_data = GUICtrlCreateDate("", 920, 50, 170, 22, $DTS_SHORTDATEFORMAT)
GUICtrlSetFont(-1, 11, 400, 2, "Calibri")
Local $sStyle = "yyyy-MM-dd"
GUICtrlSendMsg($filtro_data, $DTM_SETFORMATW, 0, $sStyle)

GUICtrlCreateLabel("filter date:", 920, 80, 110, 22)
$filtro_data2 = GUICtrlCreateDate("", 920, 100, 170, 22, $DTS_SHORTDATEFORMAT)
GUICtrlSetFont(-1, 11, 400, 2, "Calibri")
Local $sStyle2 = "yyyy-MM-dd"
GUICtrlSendMsg($filtro_data2, $DTM_SETFORMATW, 0, $sStyle2)

$applica_filtro = GUICtrlCreateButton("&cerca", 920, 430, 75, 40)
GUICtrlSetFont(-1, 11, 800, 2, "Calibri")
GUICtrlSetImage(-1, "shell32.dll", 23)

_GUIListViewEx_MsgRegister()

GUISetState(@SW_SHOW, $gui_bo)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $applica_filtro
            _GUICtrlListView_DeleteAllItems($lista)
            _GUIListViewEx_Close(0) ; Do not forget to close the ListView each time <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

            Local $filtro_ok = 0, $colonna_filtro = '', $riga_filtro = ''
            ;_sql_gettable2d(-1, "exec filtrobo'','','','" & GUICtrlRead($filtro_data) & "','" & GUICtrlRead($filtro_data2) & "','','',''", $filtro_ok, $riga_filtro, $colonna_filtro)

            ; Simulate SQL return array
            Local $filtro_ok[5][11] = [["Blah", "Blah", "Blah", "Blah", "IN LAVORAZIONE", "Blah", "Blah", "Blah", "Blah", "Blah", "Blah"], _
                                        ["Blah", "Blah", "Blah", "Blah", "Blah", "Blah", "Blah", "Blah", "Blah", "Blah", "Blah"], _
                                        ["Blah", "Blah", "Blah", "Blah", "RECLAMO CHIUSO", "Blah", "Blah", "Blah", "Blah", "Blah", "Blah"], _
                                        ["Blah", "Blah", "Blah", "Blah", "Blah", "Blah", "Blah", "Blah", "Blah", "Blah", "Blah"], _
                                        ["Blah", "Blah", "Blah", "Blah", "RECLAMO DA GESTIRE BO", "Blah", "Blah", "Blah", "Blah", "Blah", "Blah"]]
            _GUICtrlListView_AddArray($lista, $filtro_ok)

            $aLista_Array = _GUIListViewEx_ReadToArray($lista)
            $lista_int = _GUIListViewEx_Init($lista, $aLista_Array, 0, 0, True, 1 + 8 + 32)

            _GUIListViewEx_SetEditStatus($lista_int, 1)

            Local $sColour = ""
            For $i = 0 To UBound($filtro_ok) - 1
                ; Much more elegant to use a Switch structure
                Switch $filtro_ok[$i][4]
                    Case "IN LAVORAZIONE"
                        $sColour = "0xFF0000;"
                    Case "RECLAMO CHIUSO", "RECLAMO DA GESTIRE BO"
                        $sColour = "0x009900;"
                EndSwitch
                ; If the item needs colouring
                If $sColour Then
                    _GUIListViewEx_SetColour($lista_int, $sColour, $i, 4)
                    $sColour = ""
                EndIf
            Next

    EndSwitch

    _GUIListViewEx_EventMonitor() ; You will need this if you want to edit coloumn 1 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
WEnd

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

PINTO1927,

No problem - it is a complex UDF and it often takes me a couple of goes to get it to do what I want!

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

 

melba last question, if I wanted to get through a botton, the value of the first selected cell? in the library of the AutoIt I get this:

 

$iIndex = _GUICtrlListView_GetSelectedIndices($lista)
$data_selezione = _GUICtrlListView_GetItemText($lista,Int($iIndex), 0)

MsgBox(0, "Test", $data_selezione)

 

Link to comment
Share on other sites

  • Moderators

PINTO1927,

Firstly you need to add an extended style:

_GUICtrlListView_SetExtendedListViewStyle ($lista, $LVS_EX_FULLROWSELECT)

Then you can use a function from within the UDF itself:

Case $cButton
    ; Get last mouse selection
    $aSel = StringSplit(_GUIListViewEx_GetLastSelItem($lista_int), "|")
    ; Confirm it is valid
    If UBound($aSel) = 4 Then
        $data_selezione = _GUICtrlListView_GetItemText($lista, $aSel[2], $aSel[3])
        MsgBox(0, "Test", $data_selezione)
    EndIf

If you only ever want a specific subitem you can replace $aSel[3] with the column value.

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

PINTO1927,

If you just want the text of the first cell, then replace $aSel[3] with 0 - and you then do not need the extended style. But the colouring code does interfere with the standard selection mode, so you need an initial mouse selection - you win some and you lose some.

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