ListIconGadget & checkbox states

Just starting out? Need help? Post your questions and find answers here.
Phant0m``

ListIconGadget & checkbox states

Post by Phant0m`` »

Hi

I’ve been fiddling a bit with ListIconGadget, and realized there doesn’t appear to be a proper implementation for PB commands to detect fully the state of a checkbox for when an item becomes checked or unchecked. And this is a problem when clicking directly on a ListIconGadget checkboxes, if I were to select a line and not try to change a line checkbox state, correct line information returns that allows me to retrieve the actual state of that line checkbox, but if there is no selection in ListIconGadget and you check or uncheck directly on a checkbox there is a problem and if there is a selection in a ListIconGadget and you check or uncheck directly a checkbox which is other-than the selected line then that is a problem in addition.

Now I could simply read every line in a ListIconGadget, and check its checkbox state but I were trying to avoid this for large list of items by making a cache of all which gets changed from the original state (for increase speed).
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

See if this helps...

Code: Select all

#LVN_ITEMCHANGED = #LVN_FIRST-1 
#MyWindow = 0 
#MyGadget = 1 
Procedure myWindowCallback(hWnd, msg, wParam, lParam) 
  result = #PB_ProcessPureBasicEvents 
  Select msg 
    Case #WM_NOTIFY 
      *pnmhdr.NMHDR = lParam 
      Select *pnmhdr\code 
        Case #LVN_ITEMCHANGED 
          *lvChange.NMLISTVIEW = lParam 
          Debug *lvChange\uNewState >>12 &$FFFF
          ;--> Read the State image mask value ( 1 = un-checked   2 = checked
          Select *lvChange\uNewState >>12 &$FFFF
            Case 1 
              StatusBarText(0, 0, "Item " + Str(*lvChange\iItem) + " has been un-checked") 
            Case 2
              StatusBarText(0, 0, "Item " + Str(*lvChange\iItem) + " has been checked") 
          EndSelect 
      EndSelect 
  EndSelect 
  ProcedureReturn result 
EndProcedure 
If OpenWindow(#MyWindow, 100, 100, 350, 140, #PB_Window_SystemMenu | #PB_Window_ScreenCentered, "ListIcon Test") And CreateGadgetList(WindowID()) 
  CreateStatusBar(0, WindowID()) 
  ListIconGadget(#MyGadget, 5, 5, 340, 110, "Name", 100, #PB_ListIcon_CheckBoxes | #PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection) 
  AddGadgetColumn(#MyGadget, 1, "Address", 250) 
  AddGadgetItem(#MyGadget, -1, "Harry Rannit" + Chr(10) + "12 Parliament Way, Battle Street, By the Bay") 
  AddGadgetItem(#MyGadget, -1, "Ginger Brokeit" + Chr(10) + "130 PureBasic Road, BigTown, CodeCity") 
  SetWindowCallback(@myWindowCallback()) 
  Repeat 
    event = WaitWindowEvent() 
  Until event = #PB_Event_CloseWindow 
EndIf 
*Edited to fix code*
Last edited by Sparkie on Sun Mar 20, 2005 4:14 am, edited 1 time in total.
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> See if this helps

Your code has a bug somewhere, Sparkie... run it and do this:

(1) Click Ginger's name (not her checkbox).
(2) Click Harry's checkbox.
(3) Click Ginger's checkbox.
(4) Repeat (3) and Ginger's state doesn't change anymore...

:?

(A native command to get the checkbox state of a ListIconGadget item would be nice).
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Phant0m``

Post by Phant0m`` »

Thanks Sparkie

This is something I was looking for as an alternative code, would be nice however to see fully working PB command to retrieve checkbox state. Anyways, thanks :)
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

:oops: Must have left something behind in the copy/paste. I'll go back and redo for you. :)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Phant0m``

Post by Phant0m`` »

:?
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Ok, it wasn't a copy/paste issue. it was a Sparkie issue. :P

I've edited the code above so it should work now.
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Phant0m``

Post by Phant0m`` »

Sparkie! You da man! :wink:
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

I have my moments. :wink:
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
UserOfPure
Enthusiast
Enthusiast
Posts: 469
Joined: Sun Mar 16, 2008 9:18 am

Post by UserOfPure »

Dear team, do you think it's possible for the GetGadgetState() command to return the ListIconGadget item when a checkbox is checked, like in Sparkie's example? At the moment the command only returns which item is selected, and takes no consideration if a checkbox is actioned. I think a checkbox action should override any item selection so that GetGadgetState() shows which item had its checkbox checked.
Joris
Addict
Addict
Posts: 890
Joined: Fri Oct 16, 2009 10:12 am
Location: BE

Re:

Post by Joris »

UserOfPure wrote:Dear team, do you think it's possible for the GetGadgetState() command to return the ListIconGadget item when a checkbox is checked, like in Sparkie's example? At the moment the command only returns which item is selected, and takes no consideration if a checkbox is actioned. I think a checkbox action should override any item selection so that GetGadgetState() shows which item had its checkbox checked.
+1

Thanks.
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.
User avatar
em_uk
Enthusiast
Enthusiast
Posts: 366
Joined: Sun Aug 08, 2010 3:32 pm
Location: Manchester UK

Re: ListIconGadget & checkbox states

Post by em_uk »

Isn't this already implemented?

Code: Select all

If GetGadgetItemState(#List,1) & #PB_ListIcon_Checked
 do stuff
Endif
If the above line is selected and ticked then do stuff.
----

R Tape loading error, 0:1
Joris
Addict
Addict
Posts: 890
Joined: Fri Oct 16, 2009 10:12 am
Location: BE

Re: ListIconGadget & checkbox states

Post by Joris »

em_uk wrote:Isn't this already implemented?

Code: Select all

If GetGadgetItemState(#List,1) & #PB_ListIcon_Checked
 do stuff
Endif
If the above line is selected and ticked then do stuff.
No.
For GetGadgetItemState you need the item index to know from which item you wont the state, and that isn't 'send' when the check is placed.
(with api's this is possible...)
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.
Post Reply