Datus Posted January 27, 2009 Share Posted January 27, 2009 (edited) Im building an array with values in it which I then use to populate a row on a list view. What i am trying to achieve is to show a square (or .jpg if need be) yellow or red as warning symbols. This is how i build my array Dim $DispArray [1] [8] $DispArray [0] [0] = "Warning0" $DispArray [0] [1] = "Warning1" $DispArray [0] [2] = "Warning2" $DispArray [0] [3] = "Warning3" $DispArray [0] [4] = "Warning4" $DispArray [0] [5] = "Warning5" $DispArray [0] [6] = "Warning6" $DispArray [0] [7] = "Warning7" What I would like to do is something like this $DispArray [0] [0] = _CreateSolidBitMap (0xFF0000, 16, 16) I then use the array to populate the list _GUICtrlListView_AddArray($FilmListDisp,$DispArray ) Anyone got any easy idea's. I have spent some time searching forum etc but its not been fruitfull. Edited January 29, 2009 by Datus We live as we dream alone! Link to comment Share on other sites More sharing options...
martin Posted January 27, 2009 Share Posted January 27, 2009 Im building an array with values in it which I then use to populate a row on a list view.What i am trying to achieve is to show a square (or .jpg if need be) yellow or red as warning symbols.This is how i build my array Dim $DispArray [1] [8] $DispArray [0] [0] = "Warning0" $DispArray [0] [1] = "Warning1" $DispArray [0] [2] = "Warning2" $DispArray [0] [3] = "Warning3" $DispArray [0] [4] = "Warning4" $DispArray [0] [5] = "Warning5" $DispArray [0] [6] = "Warning6" $DispArray [0] [7] = "Warning7"What I would like to do is something like this$DispArray [0] [0] = _CreateSolidBitMap (0xFF0000, 16, 16)I then use the array to populate the list_GUICtrlListView_AddArray($FilmListDisp,$DispArray )Anyone got any easy idea's.I have spent some time searching forum etc but its not been fruitfull.Have you looked at the _GUICtrlListView_SetImageList example in the help? That looks to me to be what you need. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Datus Posted January 28, 2009 Author Share Posted January 28, 2009 Yes I have been looking at those examples. Just had another go and managed to get something. I will post my results in the next few hours whilst I evaluate the results. Thanks for replying....... We live as we dream alone! Link to comment Share on other sites More sharing options...
Datus Posted January 28, 2009 Author Share Posted January 28, 2009 Took a bit of messing to get it to work but here is the code for others expandcollapse popup#include <GuiConstantsEx.au3> #include <GuiListView.au3> #include <GuiImageList.au3> Dim $DispArray [1] [4] GUICreate("(Internal) ListView Set Item State", 750,550, -1, -1) $hListView = GUICtrlCreateListView("Status|Server|Drv|GB Total", 125,25,610,430) GUISetState() ; Load images $hImage = _GUIImageList_Create () _GUIImageList_Add ($hImage, _GUICtrlListView_CreateSolidBitMap (GUICtrlGetHandle($hListView), 0xFF0000, 16, 16));Red _GUIImageList_Add ($hImage, _GUICtrlListView_CreateSolidBitMap (GUICtrlGetHandle($hListView), 0xffff00, 16, 16));Yellow _GUIImageList_Add ($hImage, _GUICtrlListView_CreateSolidBitMap (GUICtrlGetHandle($hListView), 0x00FF00, 16, 16));Green _GUICtrlListView_SetImageList ($hListView, $hImage, 2);2 seems to insert a column to allow you to put an image in ; Set columns width _GUICtrlListView_SetColumnWidth ($hListView, 0, 80) _GUICtrlListView_SetColumnWidth ($hListView, 1, 80) _GUICtrlListView_SetColumnWidth ($hListView, 2, 80) _GUICtrlListView_SetColumnWidth ($hListView, 3, 80) For $x = 1 to 10 $DispArray [0] [0] = $x $DispArray [0] [1] = "Server" $DispArray [0] [2] = "Warning2" $DispArray [0] [3] = "Warning3" _GUICtrlListView_AddArray($hListView,$DispArray ) If $x = 5 then _GUICtrlListView_SetItemStateImage ($hListView, 0, 1);pick colour 1 = red ElseIf $x = 7 then _GUICtrlListView_SetItemStateImage ($hListView, 0, 2);pick colour 2 = yellow Else _GUICtrlListView_SetItemStateImage ($hListView, 0, 3);pick colour 3 = green EndIf Next Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() Exit Now this is the bit I will test next and that is column sorting. Will advise if this works or not. We live as we dream alone! Link to comment Share on other sites More sharing options...
Datus Posted January 28, 2009 Author Share Posted January 28, 2009 Nope it did't work with this sort routine, any sugestions or back to my original question. expandcollapse popup#include <GuiConstantsEx.au3> #include <GuiListView.au3> #include <GuiImageList.au3> Dim $DispArray [1] [4] GUICreate("(Internal) ListView Set Item State", 750,550, -1, -1) $hListView = GUICtrlCreateListView("Status|Server|Drv|GB Total", 125,25,610,430) GUISetState() $B_DESCENDING=_GUICtrlListView_GetColumnCount ($hListView) GUIRegisterMsg($WM_NOTIFY, "SortView") ; Load images $hImage = _GUIImageList_Create () _GUIImageList_Add ($hImage, _GUICtrlListView_CreateSolidBitMap (GUICtrlGetHandle($hListView), 0xFF0000, 16, 16));Red _GUIImageList_Add ($hImage, _GUICtrlListView_CreateSolidBitMap (GUICtrlGetHandle($hListView), 0xffff00, 16, 16));Yellow _GUIImageList_Add ($hImage, _GUICtrlListView_CreateSolidBitMap (GUICtrlGetHandle($hListView), 0x00FF00, 16, 16));Green _GUICtrlListView_SetImageList ($hListView, $hImage, 2);2 seems to insert a column to allow you to put an image in ; Set columns width _GUICtrlListView_SetColumnWidth ($hListView, 0, 80) _GUICtrlListView_SetColumnWidth ($hListView, 1, 80) _GUICtrlListView_SetColumnWidth ($hListView, 2, 80) _GUICtrlListView_SetColumnWidth ($hListView, 3, 80) For $x = 1 to 10 $DispArray [0] [0] = $x $DispArray [0] [1] = "Server" $DispArray [0] [2] = "Warning2" $DispArray [0] [3] = "Warning3" _GUICtrlListView_AddArray($hListView,$DispArray ) If $x = 5 then _GUICtrlListView_SetItemStateImage ($hListView, 0, 1);pick colour 1 = red ElseIf $x = 7 then _GUICtrlListView_SetItemStateImage ($hListView, 0, 2);pick colour 2 = yellow Else _GUICtrlListView_SetItemStateImage ($hListView, 0, 3);pick colour 3 = green EndIf Next Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() Exit Func SortView($hWnd, $iMsg, $iwParam, $ilParam) Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView $hWndListView = $hListView If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $LVN_COLUMNCLICK; A column was clicked Local $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam) _GUICtrlListView_SimpleSort ($hWndListView, $B_DESCENDING, DllStructGetData($tInfo, "SubItem")) ; No return value EndSwitch EndSwitch ;Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY We live as we dream alone! Link to comment Share on other sites More sharing options...
martin Posted January 28, 2009 Share Posted January 28, 2009 Nope it did't work with this sort routine, any sugestions or back to my original question. expandcollapse popup#include <GuiConstantsEx.au3> #include <GuiListView.au3> #include <GuiImageList.au3> Dim $DispArray [1] [4] GUICreate("(Internal) ListView Set Item State", 750,550, -1, -1) $hListView = GUICtrlCreateListView("Status|Server|Drv|GB Total", 125,25,610,430) GUISetState() $B_DESCENDING=_GUICtrlListView_GetColumnCount ($hListView) GUIRegisterMsg($WM_NOTIFY, "SortView") ; Load images $hImage = _GUIImageList_Create () _GUIImageList_Add ($hImage, _GUICtrlListView_CreateSolidBitMap (GUICtrlGetHandle($hListView), 0xFF0000, 16, 16));Red _GUIImageList_Add ($hImage, _GUICtrlListView_CreateSolidBitMap (GUICtrlGetHandle($hListView), 0xffff00, 16, 16));Yellow _GUIImageList_Add ($hImage, _GUICtrlListView_CreateSolidBitMap (GUICtrlGetHandle($hListView), 0x00FF00, 16, 16));Green _GUICtrlListView_SetImageList ($hListView, $hImage, 2);2 seems to insert a column to allow you to put an image in ; Set columns width _GUICtrlListView_SetColumnWidth ($hListView, 0, 80) _GUICtrlListView_SetColumnWidth ($hListView, 1, 80) _GUICtrlListView_SetColumnWidth ($hListView, 2, 80) _GUICtrlListView_SetColumnWidth ($hListView, 3, 80) For $x = 1 to 10 $DispArray [0] [0] = $x $DispArray [0] [1] = "Server" $DispArray [0] [2] = "Warning2" $DispArray [0] [3] = "Warning3" _GUICtrlListView_AddArray($hListView,$DispArray ) If $x = 5 then _GUICtrlListView_SetItemStateImage ($hListView, 0, 1);pick colour 1 = red ElseIf $x = 7 then _GUICtrlListView_SetItemStateImage ($hListView, 0, 2);pick colour 2 = yellow Else _GUICtrlListView_SetItemStateImage ($hListView, 0, 3);pick colour 3 = green EndIf Next Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() Exit Func SortView($hWnd, $iMsg, $iwParam, $ilParam) Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView $hWndListView = $hListView If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $LVN_COLUMNCLICK; A column was clicked Local $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam) _GUICtrlListView_SimpleSort ($hWndListView, $B_DESCENDING, DllStructGetData($tInfo, "SubItem")) ; No return value EndSwitch EndSwitch ;Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY You could do something like this to sort the bitmaps after sorting the lines. expandcollapse popup#include <GuiConstantsEx.au3> #include <GuiListView.au3> #include <GuiImageList.au3> #include <windowsconstants.au3> Dim $DispArray[1][5] GUICreate("(Internal) ListView Set Item State", 750, 550, -1, -1) $hListView = GUICtrlCreateListView("Status|Server|Drv|GB Total", 125, 25, 610, 430) GUISetState() $B_DESCENDING = _GUICtrlListView_GetColumnCount($hListView) ;GUIRegisterMsg($WM_NOTIFY, "SortView") ; _GUICtrlListView_BeginUpdate($hWnd) ; Load images $hImage = _GUIImageList_Create() _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap(GUICtrlGetHandle($hListView), 0xFF0000, 16, 16));Red _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap(GUICtrlGetHandle($hListView), 0xffff00, 16, 16));Yellow _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap(GUICtrlGetHandle($hListView), 0x00FF00, 16, 16));Green _GUICtrlListView_SetImageList($hListView, $hImage, 2);2 seems to insert a column to allow you to put an image in ; Set columns width _GUICtrlListView_SetColumnWidth($hListView, 0, 80) _GUICtrlListView_SetColumnWidth($hListView, 1, 80) _GUICtrlListView_SetColumnWidth($hListView, 2, 80) _GUICtrlListView_SetColumnWidth($hListView, 3, 80) For $x = 1 To 10 $DispArray[0][0] = $x $DispArray[0][1] = "Server" $DispArray[0][2] = "Warning2" $DispArray[0][3] = "Warning3" _GUICtrlListView_AddArray($hListView, $DispArray) Next For $x = 0 To 9 If $x = 5 Then _GUICtrlListView_SetItemStateImage($hListView, $x, 1);pick colour 1 = red ElseIf $x = 7 Then _GUICtrlListView_SetItemStateImage($hListView, $x, 2);pick colour 2 = yellow Else _GUICtrlListView_SetItemStateImage($hListView, $x, 3);pick colour 3 = green EndIf Next GUIRegisterMsg($WM_NOTIFY, "SortView") Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() Exit Func SortView($hWnd, $iMsg, $iwParam, $ilParam) Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView $hWndListView = $hListView If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $LVN_COLUMNCLICK; A column was clicked Local $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam) _GUICtrlListView_SimpleSort($hWndListView, $B_DESCENDING, DllStructGetData($tInfo, "SubItem")) ; No return value EndSwitch EndSwitch For $x = 0 To 9 If _GUICtrlListView_GetItemText($hWndListView, $x) = 5 Then _GUICtrlListView_SetItemStateImage($hListView, $x, 1);pick colour 1 = red ElseIf _GUICtrlListView_GetItemText($hWndListView, $x) = 3 Then _GUICtrlListView_SetItemStateImage($hListView, $x, 2);pick colour 2 = yellow Else _GUICtrlListView_SetItemStateImage($hListView, $x, 3);pick colour 3 = green EndIf Next ;Return $GUI_RUNDEFMSG EndFunc ;==>SortView The first time you clock on the heading it doesn't sort but I haven't worried about that for this post. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Datus Posted January 29, 2009 Author Share Posted January 29, 2009 Thanks for both replies Martin. I see what you've done which is to read the list after sorting and re-apply the colours. I have amended the code for others in the sort area to count how many rows there are in the list as my example populated it with 10 records but real world code there will be random number of records. Hope one day Autoit can pump some developement time into perhaps making these type of GUI handling issues a bit easier. expandcollapse popup#include <GuiConstantsEx.au3> #include <GuiListView.au3> #include <GuiImageList.au3> #include <windowsconstants.au3> Dim $DispArray[1][5] GUICreate("(Internal) ListView Set Item State", 750, 550, -1, -1) $hListView = GUICtrlCreateListView("Status|Server|Drv|GB Total", 125, 25, 610, 430) GUISetState() $B_DESCENDING = _GUICtrlListView_GetColumnCount($hListView) ;GUIRegisterMsg($WM_NOTIFY, "SortView") ; _GUICtrlListView_BeginUpdate($hWnd) ; Load images $hImage = _GUIImageList_Create() _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap(GUICtrlGetHandle($hListView), 0xFF0000, 16, 16));Red _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap(GUICtrlGetHandle($hListView), 0xffff00, 16, 16));Yellow _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap(GUICtrlGetHandle($hListView), 0x00FF00, 16, 16));Green _GUICtrlListView_SetImageList($hListView, $hImage, 2);2 seems to insert a column to allow you to put an image in ; Set columns width _GUICtrlListView_SetColumnWidth($hListView, 0, 80) _GUICtrlListView_SetColumnWidth($hListView, 1, 80) _GUICtrlListView_SetColumnWidth($hListView, 2, 80) _GUICtrlListView_SetColumnWidth($hListView, 3, 80) For $x = 1 To 10 $DispArray[0][0] = $x $DispArray[0][1] = "Server" $DispArray[0][2] = "Warning2" $DispArray[0][3] = "Warning3" _GUICtrlListView_AddArray($hListView, $DispArray) Next For $x = 0 To 9 If $x = 5 Then _GUICtrlListView_SetItemStateImage($hListView, $x, 1);pick colour 1 = red ElseIf $x = 7 Then _GUICtrlListView_SetItemStateImage($hListView, $x, 2);pick colour 2 = yellow Else _GUICtrlListView_SetItemStateImage($hListView, $x, 3);pick colour 3 = green EndIf Next GUIRegisterMsg($WM_NOTIFY, "SortView") Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() Exit Func SortView($hWnd, $iMsg, $iwParam, $ilParam) Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $ListRowCount $hWndListView = $hListView If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $LVN_COLUMNCLICK; A column was clicked Local $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam) _GUICtrlListView_SimpleSort($hWndListView, $B_DESCENDING, DllStructGetData($tInfo, "SubItem")) ; No return value EndSwitch EndSwitch $ListRowCount = _GUICtrlListView_GetItemCount($hListView) For $x = 0 To $ListRowCount -1 If _GUICtrlListView_GetItemText($hWndListView, $x) = 5 Then _GUICtrlListView_SetItemStateImage($hListView, $x, 1);pick colour 1 = red ElseIf _GUICtrlListView_GetItemText($hWndListView, $x) = 3 Then _GUICtrlListView_SetItemStateImage($hListView, $x, 2);pick colour 2 = yellow Else _GUICtrlListView_SetItemStateImage($hListView, $x, 3);pick colour 3 = green EndIf Next ;Return $GUI_RUNDEFMSG EndFunc ;==>SortView We live as we dream alone! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now