Primary key while interpreting data in ListIconGadget

Everything else that doesn't fall into one of the other PB categories.
User avatar
bbanelli
Enthusiast
Enthusiast
Posts: 544
Joined: Tue May 28, 2013 10:51 pm
Location: Europe
Contact:

Primary key while interpreting data in ListIconGadget

Post by bbanelli »

Greetings to all,

I have noticed that there is no (easy, or perhaps at all while considering multiplatform approach) to hide column in ListIconGadget, while this is essential in dealing with databases where you have to remember primary key in order to process further queries. In Windows, partial workaround is to make column width '0', but that doesn't work on other OS'es.

For that purpose, I am using the following structure:

Code: Select all

Structure DatabaseRow
  ID.i
  Array Columns.s(1)
EndStructure
so when selecting rows from database, I remember them with something like this

Code: Select all

NewList ListView().DatabaseRow
;Our imaginary query with 11 columns, 1st column is primary key and other 10
;are displayed in ListViewGadget
;...
While NextDatabaseRow(0)
  AddElement (ListView())
  ListView()\ID = Val(GetDatabaseString(0, 0))
  ReDim ListView()\Columns(9)
  For i = 1 To 10
    ListView()\Columns(i - 1) = GetDatabaseString(0, i)
  Next
Wend
And when I access them from ListIconGadget I merely use

Code: Select all

SelectElement(ListView(), GetGadgetState(#ListViewGadget))
to access appropriate one in the list.

Is there any more elegant way for that?
"If you lie to the compiler, it will get its revenge."
Henry Spencer
https://www.pci-z.com/
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8453
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Primary key while interpreting data in ListIconGadget

Post by netmaestro »

You might consider Set/GetGadgetItemData for this, it seems perfect.
BERESHEIT
User avatar
bbanelli
Enthusiast
Enthusiast
Posts: 544
Joined: Tue May 28, 2013 10:51 pm
Location: Europe
Contact:

Re: Primary key while interpreting data in ListIconGadget

Post by bbanelli »

netmaestro wrote:You might consider Set/GetGadgetItemData for this, it seems perfect.
Is cursing forbidden with forum rules?

This is exactly what I need, however, I have never realized that function exists! :(

netmaestro, thank you very much for giving me a little RTFM tour; PB team, sorry for doubting you. :)
"If you lie to the compiler, it will get its revenge."
Henry Spencer
https://www.pci-z.com/
Post Reply