Posted: Sun Dec 12, 2004 6:59 pm
PB_AlwaysShowSelection Also works now ... only one to go! 

http://www.purebasic.com
https://www.purebasic.fr/english/
Code: Select all
;-- SetLIGadgetItemColor
#NM_CUSTOMDRAW = -12 ; $FFFFFFF4
#CDRF_DODEFAULT = $0
#CDDS_PREPAINT = 1 ; $00000001
#CDRF_NOTIFYITEMDRAW = 32 ; $00000020
#CDRF_NEWFONT = 2 ; $00000002
#CDDS_ITEM = 65536 ; $00010000
#CDDS_ITEMPREPAINT = #CDDS_ITEM | #CDDS_PREPAINT
;- Constants
#Window_Main_ID = 0
#Window_Main_Width = 500
#Window_Main_Height = 500
#Gadget_ListIcon_ID = 0
;- Variables
Global WMID.l ; - Handle of the main window
;- Procedures
Procedure SetLIGadgetItemColor(GadgetID.l, lParam.l)
*nml.NMLVCUSTOMDRAW = lParam
; - Copy CustomDraw Structure
Select *nml\nmcd\dwDrawStage
Case #CDDS_PREPAINT ; - tell Windows that every line has to be painted seperatly
Result = #CDRF_NOTIFYITEMDRAW
Case #CDDS_ITEMPREPAINT ; - colorize lines
If *nml\nmcd\hdr\idFrom = GadgetID
For a = 0 To CountGadgetItems(GadgetID)
If *nml\nmcd\dwItemSpec = a
; - paint text red if column 2 is non-zero
If GetGadgetItemText(GadgetID, a, 1) <> "0"
*nml\clrTextBk = RGB(200, 0, 0) ; Background Color
*nml\clrText = RGB(255, 255, 255) ; Text Color
Else
*nml\clrTextBk = RGB(255, 255, 255) ; Background Color
*nml\clrText = RGB( 0, 0, 0) ; Text Color
EndIf
Result = #CDRF_NEWFONT
EndIf
Next a
EndIf
EndSelect
ProcedureReturn Result
EndProcedure
Procedure ColorCallback(WindowID, Message, wParam, lParam)
Result = #PB_ProcessPureBasicEvents
Select Message
Case #WM_NOTIFY
*hdr.NMHDR = lParam
Select wParam
Case #Gadget_ListIcon_ID ; - Your ListIconGadget
If *hdr\code = #NM_CUSTOMDRAW
Result = SetLIGadgetItemColor(#Gadget_ListIcon_ID, lParam)
EndIf
EndSelect
EndSelect
ProcedureReturn Result
EndProcedure
;- Program
WMID = OpenWindow(#Window_Main_ID, 0, 0, #Window_Main_Width, #Window_Main_Height, #PB_Window_SystemMenu | #PB_Window_ScreenCentered, "ListIcon with Colored Lines")
If WMID
If CreateGadgetList(WMID)
ListIconGadget(#Gadget_ListIcon_ID, 0, 0, WindowWidth(), WindowHeight(), "Column 1", 150, #PB_ListIcon_FullRowSelect)
AddGadgetColumn(#Gadget_ListIcon_ID, 1, "Column 2", WindowWidth()-155)
For a = 0 To 50
AddGadgetItem(#Gadget_ListIcon_ID, -1, "Line "+Str(a)+Chr(10)+"0")
AddGadgetItem(#Gadget_ListIcon_ID, -1, "Line "+Str(a)+Chr(10)+"Non-Zero")
Next a
EndIf
SetWindowCallback(@ColorCallback())
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
quit = #TRUE
EndSelect
Until quit = #TRUE
EndIf
Ah, a long long time ago, in a galaxy far far away...Ollivier wrote:Thank you Srod. I remember you had a code using editorgagdet for each cell (Perhaps my memory is wrong! )
In short, no! The overhead would be horrendous, the flicker would send your monitor into orbit...... It just wouldn't be worth the hassle. You will need some kind of custom solution; either a 3rd party grid control allowing for variable row-heights (have a look at xgrid or csgrid) or proceed with an owner-drawn PB ListView gadget etc.Do you think it's possible creating one little editorgadget per cell which the size is managed by splittergadgets ?