Page 1 of 1

Windows only: ListIcon: Hilight Selected Cell

Posted: Mon Jun 01, 2015 7:24 pm
by IdeasVacuum
Very tiny tip but hopefully someone will find it handy one day.
When the User clicks in a ListIcon Cell, you can capture that choice, then deselect it's row - this allows the cell back colour to be changed. Works with or without the Compiler setting "Enable Modern Theme Support".

Code: Select all

EnableExplicit

Enumeration
#WinMain
#TxtLblRow
#TxtValRow
#TxtValCol
#TxtLblCol
#ListIcon
EndEnumeration

Global      igActiveRow.i = -1
Global      igActiveCol.i = -1
Global  igPrevActiveRow.i = -1
Global  igPrevActiveCol.i = -1

Global  igHilightColour.i = RGB(065,165,200)
Global igListBackColour.i = RGB(196,196,196)

Procedure.i WinCallBackList(WinId.i, uMsg.i, wParam.i, lParam.i)
;---------------------------------------------------------------
Protected  iReturn.i = #PB_ProcessPureBasicEvents
Protected *msg.NMHDR = lParam
Protected *ListData.NMITEMACTIVATE

      Select uMsg

           Case #WM_NOTIFY

                If IsGadget(#ListIcon)

                      If( (*msg\hwndFrom = GadgetID(#ListIcon)) And ( (*msg\code = #NM_RCLICK) Or (*msg\code = #NM_CLICK) ) )

                             SetGadgetItemColor(#ListIcon, igPrevActiveRow, #PB_Gadget_BackColor, igListBackColour)

                                   *ListData = lParam
                                 igActiveRow = *ListData\iItem
                                 igActiveCol = *ListData\iSubItem
                             igPrevActiveRow = igActiveRow
                             igPrevActiveCol = igActiveCol
                             SetGadgetItemColor(#ListIcon, igActiveRow, #PB_Gadget_BackColor, igHilightColour, igActiveCol)
                                  SetGadgetText(#TxtValRow, Str(igActiveRow))
                                  SetGadgetText(#TxtValCol, Str(igActiveCol))
                             SetGadgetItemState(#ListIcon, igActiveRow, #Null)
                                     iReturn = #False
                      EndIf
                EndIf
      EndSelect

      ProcedureReturn(iReturn)
EndProcedure

Procedure WinMain()
;------------------
Protected iFlags.i = #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_ScreenCentered
Protected iFlagsList.i = #PB_ListIcon_GridLines | #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection
Protected iCol.i, iRow.i, sCell.s

              If OpenWindow(#WinMain, 0, 0, 600, 400, "Hilight Selected Cell", iFlags)

                          TextGadget(#TxtLblRow,   4,  4,  62,  20, "ROW:", #PB_Text_Right)
                          TextGadget(#TxtValRow,  72,  4,  26,  20, "", #PB_Text_Center | #PB_Text_Border)
                          TextGadget(#TxtValCol, 208,  4,  26,  20, "", #PB_Text_Center | #PB_Text_Border)
                          TextGadget(#TxtLblCol, 140,  4,  62,  20, "COL:", #PB_Text_Right)
                      ListIconGadget(#ListIcon,    0, 32, 600, 360, "Col 0", 100, iFlagsList)
                     AddGadgetColumn(#ListIcon,    1, "Col 1", 100)
                     AddGadgetColumn(#ListIcon,    2, "Col 2", 100)
                     AddGadgetColumn(#ListIcon,    3, "Col 3", 100)
                     AddGadgetColumn(#ListIcon,    4, "Col 4", 100)
                     AddGadgetColumn(#ListIcon,    5, "Col 5", 100)
                       AddGadgetItem(#ListIcon, 0, "")
                       AddGadgetItem(#ListIcon, 1, "")
                       AddGadgetItem(#ListIcon, 2, "")
                       AddGadgetItem(#ListIcon, 3, "")
                       AddGadgetItem(#ListIcon, 4, "")
                       AddGadgetItem(#ListIcon, 5, "")
                       AddGadgetItem(#ListIcon, 6, "")
                       AddGadgetItem(#ListIcon, 7, "")
                       AddGadgetItem(#ListIcon, 8, "")
                       AddGadgetItem(#ListIcon, 9, "")
                      SetGadgetColor(#ListIcon, #PB_Gadget_BackColor, igListBackColour)

                     For iCol = 0 To 5

                           For iRow = 0 To 9

                                      sCell = "Row " + Str(iRow) + " Col " + Str(iCol)
                                      SetGadgetItemText(#ListIcon, iRow, sCell, iCol)
                           Next iRow

                     Next iCol

                     SetWindowCallback(@WinCallBackList())
              EndIf
EndProcedure

Procedure WaitForUser()
;----------------------
Protected iEvent.i

              Repeat
                    iEvent = WaitWindowEvent(1)
              Until iEvent = #PB_Event_CloseWindow
EndProcedure

    WinMain()
WaitForUser()
End
[/size]