GetGadgetItemAttribute() returning wrong value

Windows specific forum
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: GetGadgetItemAttribute() returning wrong value

Post 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)))
RichardL
Enthusiast
Enthusiast
Posts: 532
Joined: Sat Sep 11, 2004 11:54 am
Location: UK

Re: GetGadgetItemAttribute() returning wrong value

Post by RichardL »

Gentlemen,
Thank you for your kind assistance
Richard
collectordave
Addict
Addict
Posts: 1310
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: GetGadgetItemAttribute() returning wrong value

Post 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
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
collectordave
Addict
Addict
Posts: 1310
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: GetGadgetItemAttribute() returning wrong value

Post 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.
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
User avatar
TI-994A
Addict
Addict
Posts: 2700
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: GetGadgetItemAttribute() returning wrong value

Post 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
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
User avatar
TI-994A
Addict
Addict
Posts: 2700
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: GetGadgetItemAttribute() returning wrong value

Post 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
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
Post Reply