ListIconGadget - Callback procedure to detect column header
ListIconGadget - Callback procedure to detect column header
Hi,
after searching and reading a lot of staff in the forums I would like to setup two questions, as I'm still learning to use PB in the right way. My question is related to the ListIconGadget which I'm using as a "FlexGrid" to display a small snapshot out of a sqlite-database.
Currently I'm searching to find a solution for...
a) How can I setup a Callback procedure that can regognize, which column header was clicked by a user in the ListIconGadget ?
b) How can I determine, which row was selected by the user (click by the user somewhere in the Gadget) ?
Does anybody know, if that is possible and maybe could share the code with the community ?
THANKS !!!
Michael
after searching and reading a lot of staff in the forums I would like to setup two questions, as I'm still learning to use PB in the right way. My question is related to the ListIconGadget which I'm using as a "FlexGrid" to display a small snapshot out of a sqlite-database.
Currently I'm searching to find a solution for...
a) How can I setup a Callback procedure that can regognize, which column header was clicked by a user in the ListIconGadget ?
b) How can I determine, which row was selected by the user (click by the user somewhere in the Gadget) ?
Does anybody know, if that is possible and maybe could share the code with the community ?
THANKS !!!
Michael
Did you allready read this topic?
viewtopic.php?t=6085&highlight=flexgrid
To set up a Callback, use the SetWindowCallback() command. Have a look
at the help of this command, to see how the procedure must look like.
PB has only one callback procedure, but it will receive all events, so also
the ones from the ListIconGadget.
Timo
viewtopic.php?t=6085&highlight=flexgrid
To set up a Callback, use the SetWindowCallback() command. Have a look
at the help of this command, to see how the procedure must look like.
PB has only one callback procedure, but it will receive all events, so also
the ones from the ListIconGadget.
Timo
quidquid Latine dictum sit altum videtur
Here is a example that shows how it's done:
Hope that helps, if not just ask...
Timo
Code: Select all
#ListIcon = 1
Procedure Callback(Window.l, Message.l, wParam.l, lParam.l)
result = #PB_ProcessPureBasicEvents
Select Message
Case #WM_NOTIFY ; these events are send as notification messages
*pnmh.NMHDR = lParam ; lParam points to a structure with more info
If *pnmh\hwndFrom = GadgetID(#ListIcon) ; see if it is the right gadget
Select *pnmh\code ; code contains actual message
Case #LVN_COLUMNCLICK ; user clicked on the Header of a column
*pnmv.NMLISTVIEW = lParam ; another info structure
Column.l = *pnmv\iSubItem ; clicked column
MessageRequester("Column Header Click","Clicked on Column "+Str(Column),0)
Case #NM_CLICK ; user clicked in the ListView
*lpnmitem.NMITEMACTIVATE = lParam
Row.l = *lpnmitem\iItem
Column.l = *lpnmitem\iSubItem
MessageRequester("Listview Click","Row: "+Str(Row)+" Column: "+Str(Column), 0)
; there is also
; #NM_DBLCLK - doublecklick
; #NM_RCLICK - right button
; #NM_RDBLCLK - right doubleclick
; they work the same as #NM_CLICK
EndSelect
EndIf
EndSelect
ProcedureReturn result
EndProcedure
If OpenWindow(0,0,0,400,400,#PB_Window_Screencentered|#PB_Window_SystemMenu, "Listicon test...")
If CreateGadgetList(WindowID())
ListIconGadget(#ListIcon, 10, 10, 380, 380, "Column0", 100,#PB_ListIcon_FullRowSelect)
; Fullrowselect must be set, because otherwiese only the first
; column will be clickable
AddGadgetColumn(#ListIcon, 1, "Column1", 100)
AddGadgetColumn(#ListIcon, 1, "Column2", 100)
AddGadgetItem(#ListIcon, 0, "Row0"+Chr(10)+"XXX"+Chr(10)+"XXX")
AddGadgetItem(#ListIcon, 1, "Row1"+Chr(10)+"XXX"+Chr(10)+"XXX")
AddGadgetItem(#ListIcon, 2, "Row2"+Chr(10)+"XXX"+Chr(10)+"XXX")
AddGadgetItem(#ListIcon, 3, "Row3"+Chr(10)+"XXX"+Chr(10)+"XXX")
SetWindowCallback(@Callback())
Repeat
Until WaitWindowEvent() = #PB_EventCloseWindow
EndIf
EndIf
End
Timo
quidquid Latine dictum sit altum videtur
All,
I was able to find the missing Structures by use of the MSDN and want to share it with use....copy this structures into the code and then it works perfect...
Structure NMLISTVIEW
hdr.NMHDR
iItem.l
iSubItem.l
uNewState.l
uOldState.l
uChanged.l
ptAction.POINT
lParam.l
EndStructure
Structure NMITEMACTIVATE
hdr.NMHDR
iItem.l
iSubItem.l
uNewState.l
uOldState.l
uChanged.l
ptAction.POINT
lParam.l
uKeyFlags.l
EndStructure
Again Thanks to Timo providing the Code
Mike
I was able to find the missing Structures by use of the MSDN and want to share it with use....copy this structures into the code and then it works perfect...

Structure NMLISTVIEW
hdr.NMHDR
iItem.l
iSubItem.l
uNewState.l
uOldState.l
uChanged.l
ptAction.POINT
lParam.l
EndStructure
Structure NMITEMACTIVATE
hdr.NMHDR
iItem.l
iSubItem.l
uNewState.l
uOldState.l
uChanged.l
ptAction.POINT
lParam.l
uKeyFlags.l
EndStructure
Again Thanks to Timo providing the Code
Mike
- Fangbeast
- PureBasic Protozoa
- Posts: 4789
- Joined: Fri Apr 25, 2003 3:08 pm
- Location: Not Sydney!!! (Bad water, no goats)
second collumn should be 2

Code: Select all
AddGadgetColumn(#ListIcon, 2, "Column2", 100)
This is probably a better idea for positioning items rather than absolute reference.
Code: Select all
AddGadgetItem(#ListIcon, -1, "Row0"+Chr(10)+"XXX"+Chr(10)+"XXX")
sorry to be a pain
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
In the ListGadget callback (NOT in the window callback!):
Code: Select all
Case #WM_LBUTTONDOWN
pInfo.LVHITTESTINFO
pInfo\pt\x = lParam&$FFFF
pInfo\pt\y = lParam>>16
SendMessage_(hWnd, #LVM_SUBITEMHITTEST, 0, pInfo)
rc.RECT
rc\top = pInfo\iSubItem
rc\left = #LVIR_BOUNDS
SendMessage_(hWnd, #LVM_GETSUBITEMRECT, pInfo\iItem, rc)
; now rc holds coords relative to ListGadget topleft corner
El_Choni
Hadn't checked Freak's code, much better for this example. Here it is, reporting subitem x and y pixel coords:
Code: Select all
#ListIcon = 1
#LVM_GETSUBITEMRECT = #LVM_FIRST+56
Structure NMLISTVIEW
hdr.NMHDR
iItem.l
iSubItem.l
uNewState.l
uOldState.l
uChanged.l
ptAction.POINT
lParam.l
EndStructure
Structure NMITEMACTIVATE
hdr.NMHDR
iItem.l
iSubItem.l
uNewState.l
uOldState.l
uChanged.l
ptAction.POINT
lParam.l
uKeyFlags.l
EndStructure
Procedure Callback(Window.l, Message.l, wParam.l, lParam.l)
result = #PB_ProcessPureBasicEvents
Select Message
Case #WM_NOTIFY ; these events are send as notification messages
*pnmh.NMHDR = lParam ; lParam points to a structure with more info
If *pnmh\hwndFrom = GadgetID(#ListIcon) ; see if it is the right gadget
Select *pnmh\code ; code contains actual message
Case #LVN_COLUMNCLICK ; user clicked on the Header of a column
*pnmv.NMLISTVIEW = lParam ; another info structure
Column.l = *pnmv\iSubItem ; clicked column
MessageRequester("Column Header Click","Clicked on Column"+Str(Column),0)
Case #NM_CLICK ; user clicked in the ListView
*lpnmitem.NMITEMACTIVATE = lParam
Row.l = *lpnmitem\iItem
Column.l = *lpnmitem\iSubItem
; there is also
; #NM_DBLCLK - doublecklick
; #NM_RCLICK - right button
; #NM_RDBLCLK - right doubleclick
; they work the same as #NM_CLICK
rc.RECT
rc\top = Column
rc\left = #LVIR_BOUNDS
SendMessage_(*pnmh\hwndFrom, #LVM_GETSUBITEMRECT, Row, rc)
; now rc holds coords relative to ListGadget topleft corner
MessageRequester("Listview Click","Row: "+Str(Row)+" Column: "+Str(Column)+Chr(10)+"Item left: "+Str(rc\left)+" Item top: "+Str(rc\top-1), 0)
EndSelect
EndIf
EndSelect
ProcedureReturn result
EndProcedure
If OpenWindow(0,0,0,400,400,#PB_Window_Screencentered|#PB_Window_SystemMenu, "Listicon test...")
If CreateGadgetList(WindowID())
ListIconGadget(#ListIcon, 10, 10, 380, 380, "Column0",100,#PB_ListIcon_FullRowSelect)
; Fullrowselect must be set, because otherwiese only the first
; column will be clickable
AddGadgetColumn(#ListIcon, 1, "Column1", 100)
AddGadgetColumn(#ListIcon, 1, "Column2", 100)
AddGadgetItem(#ListIcon, 0, "Row0"+Chr(10)+"XXX"+Chr(10)+"XXX")
AddGadgetItem(#ListIcon, 1, "Row1"+Chr(10)+"XXX"+Chr(10)+"XXX")
AddGadgetItem(#ListIcon, 2, "Row2"+Chr(10)+"XXX"+Chr(10)+"XXX")
AddGadgetItem(#ListIcon, 3, "Row3"+Chr(10)+"XXX"+Chr(10)+"XXX")
SetWindowCallback(@Callback())
Repeat
Until WaitWindowEvent() = #PB_EventCloseWindow
EndIf
EndIf
End
El_Choni