Virtual list and Listicon. What is wrong?

Just starting out? Need help? Post your questions and find answers here.
zikitrake
Addict
Addict
Posts: 834
Joined: Thu Mar 25, 2004 2:15 pm
Location: Spain

Virtual list and Listicon. What is wrong?

Post by zikitrake »

I had this old code, but it draw a wrong listicon output (PB5.70 64 - Windows 10)

Code: Select all

#ItemCount = 10
Global Dim myItems.s(0)
#LVSICF_NOINVALIDATEALL = 1 
#LVN_ODCACHEHINT = #LVN_FIRST - 13 

Procedure WinCallback(hwnd, msg, wParam, lParam) 
  result = #PB_ProcessPureBasicEvents 
  Protected field.s
  Select msg 
    Case #WM_NOTIFY 
      *pnmh.NMHDR = lParam 
      Select *pnmh\code 
        Case #LVN_ODCACHEHINT 
          result = 0 
        Case #LVN_GETDISPINFO                ;
          *pnmlvdi.NMLVDISPINFO = lParam 
          If *pnmlvdi\item\mask & #LVIF_TEXT
            line.s = myItems(*pnmlvdi\item\iItem)
            If line
              field = StringField(line, *pnmlvdi\item\iSubItem+1, #LF$)
            EndIf
            *pnmlvdi\item\pszText = @field
            ;
          EndIf          
      EndSelect 
  EndSelect 
  ProcedureReturn result 
EndProcedure 

If OpenWindow(0, 100, 100, 800, 600, "ListIcon Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  SetWindowCallback(@WinCallback()) 
  ListIconGadget(0, 5, 5, 780, 390, "A", 250,#PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection|#PB_ListIcon_MultiSelect|#LVS_OWNERDATA)  
  SendMessage_(GadgetID(0), #LVM_SETITEMCOUNT, 0, #LVSICF_NOINVALIDATEALL)
  AddGadgetColumn(0, 1, "B", 135)
  AddGadgetColumn(0, 2, "C", 135)
  
  SendMessage_(GadgetID(0), #LVM_SETITEMCOUNT, #ItemCount+1, #LVSICF_NOINVALIDATEALL)     
  
  iframe.s = "https://www.google.com/maps"
    
  For pos = 0 To #ItemCount
    ReDim myItems(pos)
    myItems(pos) = "ab" + #LF$ + iframe + #LF$ + iframe
  Next
  
  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
EndIf
Image

Thank you in advance!
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4663
Joined: Sun Apr 12, 2009 6:27 am

Re: Virtual list and Listicon. What is wrong?

Post by RASHAD »

Hi

Code: Select all

            If line
              field = StringField(line, *pnmlvdi\item\iSubItem+1,#LF$)
              PokeS(*pnmlvdi\item\pszText, Field)
            EndIf
            ;*pnmlvdi\item\pszText = @field
Egypt my love
User avatar
CELTIC88
Enthusiast
Enthusiast
Posts: 154
Joined: Thu Sep 17, 2015 3:39 pm

Re: Virtual list and Listicon. What is wrong?

Post by CELTIC88 »

your 'string item' must be declared in global!!!!!
 
'field = ' is local
interested in Cybersecurity..
zikitrake
Addict
Addict
Posts: 834
Joined: Thu Mar 25, 2004 2:15 pm
Location: Spain

Re: Virtual list and Listicon. What is wrong?

Post by zikitrake »

CELTIC88 wrote:your 'string item' must be declared in global!!!!!

'field = ' is local
RASHAD wrote:Hi

Code: Select all

            If line
              field = StringField(line, *pnmlvdi\item\iSubItem+1,#LF$)
              PokeS(*pnmlvdi\item\pszText, Field)
            EndIf
            ;*pnmlvdi\item\pszText = @field
:oops: Thank you both!
:lol: Now I have to decide which of the modifications I make. They work just as well :!:
Wolfram
Enthusiast
Enthusiast
Posts: 568
Joined: Thu May 30, 2013 4:39 pm

Re: Virtual list and Listicon. What is wrong?

Post by Wolfram »

Why do you ReDim() inside the loop?

Code: Select all

For pos = 0 To #ItemCount
    ReDim myItems(pos)
    myItems(pos) = "ab" + #LF$ + iframe + #LF$ + iframe
Next
More efficiently is:

Code: Select all

ReDim myItems(#ItemCount)
For pos = 0 To #ItemCount
    myItems(pos) = "ab" + #LF$ + iframe + #LF$ + iframe
Next
macOS Catalina 10.15.7
zikitrake
Addict
Addict
Posts: 834
Joined: Thu Mar 25, 2004 2:15 pm
Location: Spain

Re: Virtual list and Listicon. What is wrong?

Post by zikitrake »

Wolfram wrote:Why do you ReDim() inside the loop?

Code: Select all

For pos = 0 To #ItemCount
    ReDim myItems(pos)
    myItems(pos) = "ab" + #LF$ + iframe + #LF$ + iframe
Next
More efficiently is:

Code: Select all

ReDim myItems(#ItemCount)
For pos = 0 To #ItemCount
    myItems(pos) = "ab" + #LF$ + iframe + #LF$ + iframe
Next
Hi, it's just an example. I put it inside because in the real program the lines are generated on the fly, with variable values, and are not always the same number of lines
Post Reply