Editing cells in ListIcons (updated for Vista)
Okay, the following is not great because use of SetGadgetColor() introduces a lot of flicker because it invalidates the whole listicon control. Getting around this would involve a little more work (using the subclassed procedure in the main 'Edit listicon.pbi' file, adding a #WM_LBUTTONDOWN handler with the hit-testing, getting the cell rectangle so that it can be invalidated, adding a little custom draw ...) More work than I have time for right now!
Code: Select all
XIncludeFile "Edit ListIcon.pbi"
DisableExplicit
oldItem = -1
LoadFont(1, "Arial",10)
If OpenWindow(0, 100, 100, 600, 600, "ListIcon Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
ListIconGadget(1, 5, 5, 490, 390, "", 0, #PB_ListIcon_GridLines)
SetGadgetFont(1, FontID(1))
For i = 1 To 30
AddGadgetColumn(1, i, "Col "+Str(i), 100)
Next
For row = 1 To 10
AddGadgetItem(1,-1,"")
For col = 1 To 100
SetGadgetItemText(1, row-1, "row "+Str(row-1)+", col "+Str(col), col)
Next
Next
SetListIconEditable(1)
SetActiveGadget(1)
; EditCell(1, 19, 5)
Repeat
Event = WaitWindowEvent()
Select event
Case #PB_Event_Gadget
Select EventGadget()
Case 1
If EventType() = #PB_EventType_LeftClick
PInfo.LVHITTESTINFO
hWnd = GadgetID(1)
GetCursorPos_(@PInfo\pt)
MapWindowPoints_(0, hWnd, @PInfo\pt, 1)
SendMessage_(hWnd, #LVM_SUBITEMHITTEST, 0, PInfo)
If PInfo\iItem<>-1
If oldItem <> -1
SetGadgetItemColor(1, oldItem, #PB_Gadget_BackColor, #White,1)
SetGadgetItemColor(1, oldItem, #PB_Gadget_FrontColor, 0,1)
EndIf
oldItem = PInfo\iItem
SetGadgetItemColor(1, oldItem, #PB_Gadget_BackColor, GetSysColor_(#COLOR_HIGHLIGHT),1)
SetGadgetItemColor(1, oldItem, #PB_Gadget_FrontColor, GetSysColor_(#COLOR_HIGHLIGHTTEXT),1)
EndIf
EndIf
EndSelect
EndSelect
Until Event = #PB_Event_CloseWindow
EndIf
I may look like a mule, but I'm not a complete ass.
- Fangbeast
- PureBasic Protozoa
- Posts: 4789
- Joined: Fri Apr 25, 2003 3:08 pm
- Location: Not Sydney!!! (Bad water, no goats)
Mister kipper tits, stop abusing those French poodles for a moment. I need to ask you something (EVIL GRIN).
Been playing with this magnificent bit of jiggery pokery and it's extremely useful.
I'd like to fire off my own event for a particular gadget when the label has started being edited (I want to strip a character), when the label has finished being edited (I want to add a character) and then I want to fire off a custom procedure immediately after.
Could you; oh sage of wisdom, elucidate at which point in your code I might put my own to accomplish this?
I failed to do so on my mortal own.
Been playing with this magnificent bit of jiggery pokery and it's extremely useful.
I'd like to fire off my own event for a particular gadget when the label has started being edited (I want to strip a character), when the label has finished being edited (I want to add a character) and then I want to fire off a custom procedure immediately after.
Could you; oh sage of wisdom, elucidate at which point in your code I might put my own to accomplish this?
I failed to do so on my mortal own.
- Arctic Fox
- Enthusiast
- Posts: 609
- Joined: Sun Dec 21, 2008 5:02 pm
- Location: Aarhus, Denmark
Re: Editing cells in ListIcons (updated for Vista)
Try
at the beginning of the _LIEEditCell()-procedure
Code: Select all
Protected Dim cols.l(0), i, blnFoundZeroColumn
Re: Editing cells in ListIcons (updated for Vista)
Thanks Arctic - I have altered the code in the first post.
I may look like a mule, but I'm not a complete ass.
- Arctic Fox
- Enthusiast
- Posts: 609
- Joined: Sun Dec 21, 2008 5:02 pm
- Location: Aarhus, Denmark
Re: Editing cells in ListIcons (updated for Vista)
And thank you too for this excellent piece of code 

Re: Editing cells in ListIcons (updated for Vista)
Hi srod,
Sorry to drag up this old thread, but I have been using your Editable Listicon code ( Procedure.l SetListIconEditable(listID) etc.. ) and it works great, but I would like to be able to un-enable a listIcon from time to time. I looked through the code and I think I have to use the SetProp_() command but when I do it kills the program or does not work.
Procedure.l UnSetListIconEditable(listID)
SetProp_(hWnd, "_LIEdit",0)
Endprocedure
Is there a simple way of doing this.
Thanks
Leo
Sorry to drag up this old thread, but I have been using your Editable Listicon code ( Procedure.l SetListIconEditable(listID) etc.. ) and it works great, but I would like to be able to un-enable a listIcon from time to time. I looked through the code and I think I have to use the SetProp_() command but when I do it kills the program or does not work.
Procedure.l UnSetListIconEditable(listID)
SetProp_(hWnd, "_LIEdit",0)
Endprocedure
Is there a simple way of doing this.
Thanks
Leo
Regards
Leo
Leo
Re: Editing cells in ListIcons (updated for Vista)
Code: Select all
Procedure UnSetListIconEditable(listID)
Protected hWnd, *mem._LIEdit
If IsGadget(listID) And GadgetType(listID)=#PB_GadgetType_ListIcon
hWnd = GadgetID(listID)
*mem = GetProp_(hWnd, "_LIEdit")
If *mem
SetWindowLongPtr_(hWnd, #GWL_WNDPROC, *mem\listOldProc)
FreeMemory(*mem)
RemoveProp_(hWnd, "_LIEdit")
EndIf
EndIf
EndProcedure
I may look like a mule, but I'm not a complete ass.
Re: Editing cells in ListIcons (updated for Vista)
Hi srod,
Thanks for that, I was a bit wide of the make with my atempt.
Thanks for that, I was a bit wide of the make with my atempt.
Regards
Leo
Leo
- Kwai chang caine
- Always Here
- Posts: 5494
- Joined: Sun Nov 05, 2006 11:42 pm
- Location: Lyon - France
Re: Editing cells in ListIcons (updated for Vista)
Hello at all
When i useI have an error at the line
in the procedure
Buit only if i use this command before
Someone know how fix it 

When i use
Code: Select all
UnSetListIconEditable(#ListIcon)
Code: Select all
If *liedit\editHwnd=0
Code: Select all
Procedure.l _LIEeditProc(hWnd, uMsg, wParam, lParam) ; ListIcon editable (Window proc of the edit control)
Protected result, oldwinproc, *liedit._LIEdit, *wpos.WINDOWPOS
;Retrieve the address of the old proc.
oldwinproc = GetProp_(hWnd, "_LIEditOldProc")
;Retrieve the address of the LIEdit structure.
*liedit = GetProp_(GetParent_(hWnd), "_LIEdit")
Select uMsg
Case #WM_ERASEBKGND
;A hack in order to clear the default selection of characters.
result=CallWindowProc_(oldwinproc, hWnd, uMsg, wParam, lParam)
If *liedit\editHwnd=0
*liedit\editHwnd = hWnd
;Set margins.
SendMessage_(hWnd, #EM_SETMARGINS, #EC_LEFTMARGIN|#EC_RIGHTMARGIN, 4)
SendMessage_(hWnd, #EM_SETSEL, -1,0)
EndIf
Case #WM_WINDOWPOSCHANGING
*wpos=lParam
;*wpos\cx=*liedit\cx ;Comment this line to get an edit control which grows with the text.
*wpos\cy=*liedit\cy+3
*wpos\x=*liedit\x
*wpos\y=*liedit\y-2
result=CallWindowProc_(oldwinproc, hWnd, uMsg, wParam, lParam)
Case #WM_NCDESTROY
result=CallWindowProc_(oldwinproc, hWnd, uMsg, wParam, lParam)
RemoveProp_(hWnd, "_LIEditOldProc")
Default
result=CallWindowProc_(oldwinproc, hWnd, uMsg, wParam, lParam)
EndSelect
ProcedureReturn result
EndProcedure

Code: Select all
EditCell(#ListIcon, 1, 1)


Not a destination
Re: Editing cells in ListIcons (updated for Vista)
Try the following in place of the UnSetListIconEditable() procedure.
Code: Select all
Procedure UnSetListIconEditable(listID)
Protected hWnd, *mem._LIEdit
If IsGadget(listID) And GadgetType(listID)=#PB_GadgetType_ListIcon
hWnd = GadgetID(listID)
*mem = GetProp_(hWnd, "_LIEdit")
If *mem
SendMessage_(hWnd, #LVM_EDITLABEL, 0, 0)
SetWindowLongPtr_(hWnd, #GWL_WNDPROC, *mem\listOldProc)
FreeMemory(*mem)
RemoveProp_(hWnd, "_LIEdit")
EndIf
EndIf
EndProcedure
I may look like a mule, but I'm not a complete ass.