Posted: Wed Jul 23, 2008 5:35 pm
Is API the way to do it? (highlight one cell)
I didn't find the option in PB help.
Thank you.
I didn't find the option in PB help.
Thank you.
http://www.purebasic.com
https://www.purebasic.fr/english/
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
Code: Select all
Protected Dim cols.l(0), i, blnFoundZeroColumn
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
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)
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