Page 1 of 2

Re: GetGadgetItemAttribute() returning wrong value

Posted: Sun Aug 10, 2014 8:56 pm
by Shardik
Rashad,

you have a small error in your interesting last code example. You have to change

Code: Select all

CompilerIf #PB_OS_Windows
to

Code: Select all

CompilerIf #PB_Compiler_OS = #PB_OS_Windows
This is a short cross-platform example using platform-specific API functions to count all columns of a ListIconGadget:

Code: Select all

Procedure.I GetNumberOfColumns(ListIconGadgetID.I)
  Protected NumberOfColumns.I

  CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_Linux
      Protected *ListStore.GtkListStore
      *ListStore = gtk_tree_view_get_model_(GadgetID(ListIconGadgetID))
      NumberOfColumns = (*ListStore\n_columns - 3) / 3
    CompilerCase #PB_OS_MacOS
      NumberOfColumns = CocoaMessage(0, GadgetID(ListIconGadgetID),
        "numberOfColumns")
    CompilerCase #PB_OS_Windows
      NumberOfColumns = SendMessage_(SendMessage_(GadgetID(ListIconGadgetID),
        #LVM_GETHEADER, 0, 0), #HDM_GETITEMCOUNT, 0, 0)
  CompilerEndSelect

  ProcedureReturn NumberOfColumns
EndProcedure

OpenWindow(0, 270, 100, 270, 60, "ListIconGadget")
ListIconGadget(0, 5, 5, WindowWidth(0) - 10, WindowHeight(0) - 10, "Column 1", 80)
AddGadgetColumn(0, 1, "Column 2", 80)
AddGadgetColumn(0, 2, "Column 3", 80)

MessageRequester("Info", "Number of columns: " + Str(GetNumberOfColumns(0)))

Re: GetGadgetItemAttribute() returning wrong value

Posted: Wed Aug 13, 2014 8:56 am
by RichardL
Gentlemen,
Thank you for your kind assistance
Richard

Re: GetGadgetItemAttribute() returning wrong value

Posted: Wed Jan 06, 2016 9:45 am
by collectordave
Counting Columns in listicon

Can you use

Code: Select all

  ColCount = 0
  While GetGadgetItemText(0,-1,ColCount) <> ""  ;Checks header text assumes all headers have some text
    ColCount + 1                                             ; count the columns
  Wend

Re: GetGadgetItemAttribute() returning wrong value

Posted: Wed Jan 06, 2016 9:57 am
by collectordave
Just noticed a funny thing while removing columns I was using

Code: Select all

  For iloop = 1 To ColCount   ;Do not remove column 0
    RemoveGadgetColumn(lstResult, iloop)
  Next
Which left a couple of columns each time changed to

Code: Select all

  For iloop = ColCount To 1 Step -1  ;Do not remove column 0
    RemoveGadgetColumn(lstResult, iloop)
  Next
And it works removing all columns except the first column.

Re: GetGadgetItemAttribute() returning wrong value

Posted: Wed Jan 06, 2016 10:20 am
by TI-994A
collectordave wrote:Counting Columns in listicon

Can you use

Code: Select all

  ColCount = 0
  While GetGadgetItemText(0,-1,ColCount) <> ""  ;Checks header text assumes all headers have some text
    ColCount + 1                                             ; count the columns
  Wend
Apparently so, as demonstrated in this working example by Kiffi:

> count colums in a listicongadget

Re: GetGadgetItemAttribute() returning wrong value

Posted: Wed Jan 06, 2016 10:21 am
by TI-994A
collectordave wrote:Just noticed a funny thing while removing columns I was using

Code: Select all

  For iloop = 1 To ColCount   ;Do not remove column 0
    RemoveGadgetColumn(lstResult, iloop)
  Next
Which left a couple of columns each time...
It should be:

Code: Select all

  For iloop = 1 To ColCount
    RemoveGadgetColumn(lstResult, 1)
  Next