(Solved) Set the header of one ListIconGadget column only to bold?

Windows specific forum
ozzie
Enthusiast
Enthusiast
Posts: 443
Joined: Sun Apr 06, 2008 12:54 pm
Location: Brisbane, Qld, Australia
Contact:

(Solved) Set the header of one ListIconGadget column only to bold?

Post by ozzie »

I'm using SetWindowCallback and an associated procedure to successfully set either bold or normal font to the row values in a column determined by another gadget's setting in that window. I've developed that from code supplied in this Forum topic: viewtopic.php?p=528096#p528096.

Is there a way in which I can also apply the bold or normal setting to the column's title? The titles of other columns must remain at the normal (initial) font.
Last edited by ozzie on Tue May 06, 2025 4:27 am, edited 1 time in total.
User avatar
jacdelad
Addict
Addict
Posts: 2002
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: Set the header of one ListIconGadget column only to bold?

Post by jacdelad »

A little googling saves you from writing huge posts ("purebasic listicon header font", first result):
viewtopic.php?p=603149#p603149
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Set the header of one ListIconGadget column only to bold?

Post by Shardik »

Only for Windows:

Code: Select all

EnableExplicit

Define BoldFont.I

Procedure ChangeHeaderTextToBold(ListIconID.I)
  Shared BoldFont.I
  Protected Header.I
  
  Header = SendMessage_(GadgetID(ListIconID), #LVM_GETHEADER, 0, 0)
  SendMessage_(Header, #WM_SETFONT, FontID(BoldFont), #True)
EndProcedure

OpenWindow(0, 200, 100, 390, 96, "ListIcon with bold text headers")
ListIconGadget(0, 10, 10, WindowWidth(0) - 20, WindowHeight(0) - 20,
  "Name", 100, #PB_ListIcon_GridLines)
AddGadgetColumn(0, 1, "Address", GadgetWidth(0) - GetGadgetItemAttribute(0, 0,
  #PB_ListIcon_ColumnWidth, 0) - 2)
AddGadgetItem(0, -1, "Harry Rannit" + #LF$ +
  "12 Parliament Way, Battle Street, By the Bay")
AddGadgetItem(0, -1, "Ginger Brokeit" + #LF$ +
  "130 PureBasic Road, BigTown, CodeCity")
AddGadgetItem(0, -1, "Didi Findit" + #LF$ +
  "321 Logo Drive, Mouse House, Downtown")

BoldFont = LoadFont(#PB_Any, "Arial", 10, #PB_Font_Bold)
ChangeHeaderTextToBold(0)

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
ozzie
Enthusiast
Enthusiast
Posts: 443
Joined: Sun Apr 06, 2008 12:54 pm
Location: Brisbane, Qld, Australia
Contact:

Re: Set the header of one ListIconGadget column only to bold?

Post by ozzie »

I did search the forum and came across several topics, but the issue is that I only want to set the font of ONE column's title to bold - not all column titles.
User avatar
jacdelad
Addict
Addict
Posts: 2002
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: Set the header of one ListIconGadget column only to bold?

Post by jacdelad »

Oh, my fault. My apologies.

Anyway, the ListIconGadget (or ListView as it's called internally in Windows) is not designed for this kind of excelesque things. I would prefer creating my own gadget or changing the way my program works over adding callbacks here and there and so on. But maybe some else can help, I unfortunately can not.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
ozzie
Enthusiast
Enthusiast
Posts: 443
Joined: Sun Apr 06, 2008 12:54 pm
Location: Brisbane, Qld, Australia
Contact:

Re: Set the header of one ListIconGadget column only to bold?

Post by ozzie »

No problem. I understand it's confusing.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4952
Joined: Sun Apr 12, 2009 6:27 am

Re: Set the header of one ListIconGadget column only to bold?

Post by RASHAD »

Hi ozzie
Long time no see :)
You can play with the ListIcon() Header by subclassing it
You can change the font and/or the color of any column header
Have fun

Code: Select all


Global oldCB

Procedure sizeCB()
  ResizeGadget(0,10,10,WindowWidth(0)-20,WindowHeight(0)-20)
EndProcedure

Procedure liCB(hWnd, uMsg, WParam, LParam)
  
  Protected *NMCUSTOMDRAW.NMCUSTOMDRAW
  Protected *NMHDR.NMHDR
  Protected Result
  
  Result = CallWindowProc_(oldCB,hWnd, uMsg, wParam, lParam)
  
  Select  uMsg
    Case #WM_NOTIFY
      *NMHDR = LParam
      
      If *NMHDR\code = #NM_CUSTOMDRAW
        *NMCUSTOMDRAW = LParam
        
        Select *NMCUSTOMDRAW\dwDrawStage
          Case #CDDS_PREPAINT
            Result = #CDRF_NOTIFYITEMDRAW
          Case #CDDS_ITEMPREPAINT
            If *NMCUSTOMDRAW\dwItemSpec = 0
              If *NMCUSTOMDRAW\uItemState & #CDIS_SELECTED                  
                SetTextColor_(*NMCUSTOMDRAW\hdc, $0000FF)
              Else
                SelectObject_(*NMCUSTOMDRAW\hdc,FontID(0))
                SetTextColor_(*NMCUSTOMDRAW\hdc, $FF0000)
              EndIf                
            Else
              If *NMCUSTOMDRAW\uItemState & #CDIS_SELECTED
                SetTextColor_(*NMCUSTOMDRAW\hdc, $0000FF)
              Else
                SelectObject_(*NMCUSTOMDRAW\hdc,FontID(1))
                SetTextColor_(*NMCUSTOMDRAW\hdc, $000000)
              EndIf
            EndIf
        EndSelect
      EndIf
  EndSelect
  
  ProcedureReturn Result
EndProcedure

LoadFont(0,"Georgia",24)
LoadFont(1,"Georgia",12)
flags = #PB_Window_SystemMenu| #PB_Window_MaximizeGadget| #PB_Window_MinimizeGadget| #PB_Window_ScreenCentered | #PB_Window_SizeGadget
OpenWindow(0, 0, 0, 600, 400, "ListIconGadget with colored header text",Flags)
ListIconGadget(0, 10, 10, WindowWidth(0) - 20, WindowHeight(0) - 20, "Name", 200, #PB_ListIcon_GridLines)
AddGadgetColumn(0, 1, "Address", GadgetWidth(0) - GetGadgetItemAttribute(0, 0, #PB_ListIcon_ColumnWidth) - 4)
AddGadgetItem(0, -1, "Harry Rannit" + #LF$ + "12 Parliament Way, Battle Street, By the Bay")
AddGadgetItem(0, -1, "Ginger Brokeit" + #LF$ + "130 PureBasic Road, BigTown, CodeCity")
AddGadgetItem(0, -1, "Didi Foundit" + #LF$ + "321 Logo Drive, Mouse House, Downtown")

Header = SendMessage_(GadgetID(0), #LVM_GETHEADER, 0, 0)
SendMessage_(Header, #WM_SETFONT, FontID(0), 0)

oldCB = SetWindowLongPtr_(GadgetID(0), #GWL_WNDPROC, @liCB())

BindEvent(#PB_Event_SizeWindow,@sizeCB())

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Quit = 1
  EndSelect
Until Quit = 1

Egypt my love
ozzie
Enthusiast
Enthusiast
Posts: 443
Joined: Sun Apr 06, 2008 12:54 pm
Location: Brisbane, Qld, Australia
Contact:

Re: (Solved) Set the header of one ListIconGadget column only to bold?

Post by ozzie »

Thanks, RASHAD. Combining your latest code for the header column bold settings with earlier code that handles column bold settings for the gadget items, I've prepared the solution below. I've included a combobox where the user selects the column to be displayed bold.

Code: Select all

Global oldCB

Procedure sizeCB()
  ResizeGadget(0,#PB_Ignore,#PB_Ignore,#PB_Ignore,#PB_Ignore)
EndProcedure

Procedure winCB(hWnd,uMsg,wParam,lParam)
  Protected Result, Col
  Protected *pnmh.NMHDR,*LVCDHeader.NMLVCUSTOMDRAW
  Protected BoldCol
  
  result = #PB_ProcessPureBasicEvents
  Select uMsg
    Case #WM_NOTIFY
      ; Debug "IsGadget(0)=" + IsGadget(0)
      If IsGadget(0) ; list
          *pnmh.NMHDR = lParam
          *LVCDHeader.NMLVCUSTOMDRAW = lParam
          If *LVCDHeader\nmcd\hdr\hwndFrom = GadgetID(0)
            Select *LVCDHeader\nmcd\dwDrawStage
              Case #CDDS_ITEMPREPAINT | #CDDS_SUBITEM
                BoldCol = GetGadgetState(1) - 1
                If *LVCDHeader\iSubItem = BoldCol
                  SelectObject_(*LVCDHeader\nmcd\hdc, FontID(1))
                Else
                  SelectObject_(*LVCDHeader\nmcd\hdc, FontID(0))
                EndIf
            EndSelect
          EndIf
        EndIf
  EndSelect
  ProcedureReturn Result
EndProcedure

Procedure liCB(hWnd, uMsg, WParam, LParam)
  Protected *NMCUSTOMDRAW.NMCUSTOMDRAW
  Protected *NMHDR.NMHDR
  Protected Result
  Protected BoldCol
  
  Result = CallWindowProc_(oldCB,hWnd, uMsg, wParam, lParam)
  
  Select  uMsg
    Case #WM_NOTIFY
      *NMHDR = LParam
      
      If *NMHDR\code = #NM_CUSTOMDRAW
        *NMCUSTOMDRAW = LParam
        
        Select *NMCUSTOMDRAW\dwDrawStage
          Case #CDDS_PREPAINT
            Result = #CDRF_NOTIFYITEMDRAW
          Case #CDDS_ITEMPREPAINT
            BoldCol = GetGadgetState(1) - 1
            If *NMCUSTOMDRAW\dwItemSpec = BoldCol
              SelectObject_(*NMCUSTOMDRAW\hdc,FontID(1))
            Else
              SelectObject_(*NMCUSTOMDRAW\hdc,FontID(0))
            EndIf
        EndSelect
      EndIf
  EndSelect
  
  ProcedureReturn Result
EndProcedure

LoadFont(0,"Georgia",12)
LoadFont(1,"Georgia",12,#PB_Font_Bold)
flags = #PB_Window_SystemMenu| #PB_Window_MaximizeGadget| #PB_Window_MinimizeGadget| #PB_Window_ScreenCentered | #PB_Window_SizeGadget
OpenWindow(0, 0, 0, 800, 300, "ListIconGadget with colored header text",Flags)
SetGadgetFont(#PB_Default, FontID(0))
ListIconGadget(0, 10, 10, 780, 200, "Name", 200, #PB_ListIcon_GridLines)
AddGadgetColumn(0, 1, "Address", 400)
AddGadgetColumn(0, 2, "Phone", 100)
AddGadgetItem(0, -1, "Harry Rannit" + #LF$ + "12 Parliament Way, Battle Street, By the Bay" + #LF$ + "12345678")
AddGadgetItem(0, -1, "Ginger Brokeit" + #LF$ + "130 PureBasic Road, BigTown, CodeCity" + #LF$ + "555666")
AddGadgetItem(0, -1, "Didi Foundit" + #LF$ + "321 Logo Drive, Mouse House, Downtown" + #LF$ + "none")

TextGadget(2,5,242,120,24,"Select column",#PB_Text_Right)
ComboBoxGadget(1,130,240,100,26)
AddGadgetItem(1,-1,"")
AddGadgetItem(1,-1,"Name")
AddGadgetItem(1,-1,"Address")
AddGadgetItem(1,-1,"Phone")
SetGadgetState(1,0)

SetWindowCallback(@winCB())

Header = SendMessage_(GadgetID(0), #LVM_GETHEADER, 0, 0)
SendMessage_(Header, #WM_SETFONT, FontID(0), 0)

oldCB = SetWindowLongPtr_(GadgetID(0), #GWL_WNDPROC, @liCB())

BindEvent(#PB_Event_SizeWindow,@sizeCB())

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_Gadget
      If EventGadget() = 1 ; combobox
        If EventType() = #PB_EventType_Change
          For n = 0 To CountGadgetItems(1) - 1
            SetGadgetItemColor(0, n, #PB_Gadget_BackColor, #PB_Default, #PB_All)
          Next n
        EndIf
      EndIf
      
    Case #PB_Event_CloseWindow
      Quit = 1
  EndSelect
Until Quit = 1

RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4952
Joined: Sun Apr 12, 2009 6:27 am

Re: (Solved) Set the header of one ListIconGadget column only to bold?

Post by RASHAD »

Hi ozzie
Glad that you got what you aimed to
Next Just optimized the snippet a little bit

Code: Select all


Procedure sizeCB()
  ResizeGadget(0,#PB_Ignore,#PB_Ignore,#PB_Ignore,#PB_Ignore)
EndProcedure

Procedure winCB(hWnd,uMsg,wParam,lParam)
  Protected *NMCUSTOMDRAW.NMCUSTOMDRAW
  Protected *NMHDR.NMHDR  
  Protected *LVCDHeader.NMLVCUSTOMDRAW
  Protected BoldCol
  
  result = #PB_ProcessPureBasicEvents
  
  Select uMsg
    Case #WM_NOTIFY
      *NMHDR = lParam      
      If *NMHDR\code = #NM_CUSTOMDRAW
        *NMCUSTOMDRAW = lParam
        Select *NMCUSTOMDRAW\dwDrawStage
          Case #CDDS_PREPAINT
            Result = #CDRF_NOTIFYITEMDRAW
          Case #CDDS_ITEMPREPAINT
            BoldCol = GetGadgetState(1)-1
            If *NMCUSTOMDRAW\lItemlParam = BoldCol
              SelectObject_(*NMCUSTOMDRAW\hdc,FontID(1))
            Else
              SelectObject_(*NMCUSTOMDRAW\hdc,FontID(0))
            EndIf
        EndSelect
      EndIf
      If IsGadget(0) ; list
        *LVCDHeader = lParam
        If *LVCDHeader\nmcd\hdr\hwndFrom = GadgetID(0)
          Select *LVCDHeader\nmcd\dwDrawStage
            Case #CDDS_ITEMPREPAINT | #CDDS_SUBITEM
              BoldCol = GetGadgetState(1) - 1
              If *LVCDHeader\iSubItem = BoldCol
                SelectObject_(*LVCDHeader\nmcd\hdc, FontID(1))
              Else
                SelectObject_(*LVCDHeader\nmcd\hdc, FontID(0))
              EndIf
          EndSelect
        EndIf
      EndIf
  EndSelect
  ProcedureReturn Result
EndProcedure

LoadFont(0,"Georgia",12)
LoadFont(1,"Georgia",12,#PB_Font_Bold)
flags = #PB_Window_SystemMenu| #PB_Window_MaximizeGadget| #PB_Window_MinimizeGadget| #PB_Window_ScreenCentered | #PB_Window_SizeGadget
OpenWindow(0, 0, 0, 800, 300, "ListIconGadget with colored header text",Flags)
SetGadgetFont(#PB_Default, FontID(0))
ListIconGadget(0, 10, 10, 780, 200, "Name", 200, #PB_ListIcon_GridLines)
AddGadgetColumn(0, 1, "Address", 400)
AddGadgetColumn(0, 2, "Phone", 100)
AddGadgetItem(0, -1, "Harry Rannit" + #LF$ + "12 Parliament Way, Battle Street, By the Bay" + #LF$ + "12345678")
AddGadgetItem(0, -1, "Ginger Brokeit" + #LF$ + "130 PureBasic Road, BigTown, CodeCity" + #LF$ + "555666")
AddGadgetItem(0, -1, "Didi Foundit" + #LF$ + "321 Logo Drive, Mouse House, Downtown" + #LF$ + "none")

TextGadget(2,5,242,120,24,"Select column",#PB_Text_Right)
ComboBoxGadget(1,135,240,100,26)
AddGadgetItem(1,-1,"Blank")
AddGadgetItem(1,-1,"Name")
AddGadgetItem(1,-1,"Address")
AddGadgetItem(1,-1,"Phone")
SetGadgetState(1,0)

Header = SendMessage_(GadgetID(0), #LVM_GETHEADER, 0, 0)
SendMessage_(Header, #WM_SETFONT, FontID(0), 0)

SetWindowCallback(@winCB())

BindEvent(#PB_Event_SizeWindow,@sizeCB())

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_Gadget
      If EventGadget() = 1 ; combobox
        If EventType() = #PB_EventType_Change
          For n = 0 To CountGadgetItems(1) - 1
            SetGadgetItemColor(0, n, #PB_Gadget_BackColor, #PB_Default, #PB_All)
          Next n
        EndIf
      EndIf
      
    Case #PB_Event_CloseWindow
      Quit = 1
  EndSelect
Until Quit = 1
Edit :Bug fixed
Last edited by RASHAD on Wed May 07, 2025 5:51 am, edited 1 time in total.
Egypt my love
ozzie
Enthusiast
Enthusiast
Posts: 443
Joined: Sun Apr 06, 2008 12:54 pm
Location: Brisbane, Qld, Australia
Contact:

Re: (Solved) Set the header of one ListIconGadget column only to bold?

Post by ozzie »

RASHAD, unfortunately that's not setting the selected column title to bold - only the column text.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4952
Joined: Sun Apr 12, 2009 6:27 am

Re: (Solved) Set the header of one ListIconGadget column only to bold?

Post by RASHAD »

Hi ozzie
My configurations :
Windows 11 pro x64
PB 6.20 x86 or PB 6.20 x64

Never mind :)
If your snippet works fine with you

Happy coding mate
Egypt my love
Post Reply