Help with ListIconGadgets

Everything else that doesn't fall into one of the other PB categories.
ebs
Enthusiast
Enthusiast
Posts: 562
Joined: Fri Apr 25, 2003 11:08 pm

Help with ListIconGadgets

Post by ebs »

I have two questions about ListIconGadgets and I hope someone here can help:

1). Is it possible to eliminate the horizontal scrollbar that appears along with the vertical scrollbar? I start out with a ListIconGadget with one column and no scrollbars. As I add items, scrollbars (horizontal and vertical) appear when I exceed the number of visible lines in the list. The vertical scrollbar is fine, but I don't want the horizontal one. The list items aren't long enough to require a horizontal scrollbar, but one appears anyway. I searched the forum and looked through the API documentation, but I haven't been able to find an answer.

2). Is it possible to set the style of the ListIconGadget so that it automatically keeps the list items sorted as they are added? I could do the sorting manually if necessary, but I'm basically lazy and don't want to do work if I don't have to! :wink:

Thanks,
Eric
freak
PureBasic Team
PureBasic Team
Posts: 5948
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

That is pretty easy to do by adding some extra Windows Flags to your
ListIconGadget.

Add these Flags:
#LVS_SORTASCENDING |#LVS_NOSCROLL |#WS_VSCROLL


#LVS_SORTASCENDING makes it always sort the items in ascending order.
(there is also #LVS_SORTDESCENDING )

#LVS_NOSCROLL removes all Scrollbars, and to enable the Vertical one,
you have to specify #WS_VSCROLL

That's all...

Timo
quidquid Latine dictum sit altum videtur
ebs
Enthusiast
Enthusiast
Posts: 562
Joined: Fri Apr 25, 2003 11:08 pm

Post by ebs »

Timo,

Amazing - thank you! I guess you just have to know which flags to use (and how to use them).

If you don't mind, how about one more:

Is there a way to associate a number (long) with each list item? I'd like to save a database ID number, so I don't have to search for an item when the user selects it. Does the control have any "built-in" facility for this, or would I need to keep track of the ID numbers myself (in an array or linked list)?

I remember that Visual Basic has an "ItemData" list that would be perfect for this purpose, but I don't know if it is part of the control or something in the VB runtime.

Thanks,
Eric

P.S. Maybe...
Now that I got your help with the scrollbar flags, I might try one of my old tricks - storing the ID numbers in a "hidden" column. This would be OK as long as it doesn't cause the horizontal scrollbar to reappear.
freak
PureBasic Team
PureBasic Team
Posts: 5948
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

> I guess you just have to know which flags to use (and how to use
them).

Yep, see here:
http://msdn.microsoft.com/library/defau ... styles.asp
http://msdn.microsoft.com/library/defau ... Styles.asp

You just have to know where to look :lol:
(Sometimes you can't set all Flags directly at the creaton of a PB Gadget,
but that's another story)

About the LONG Values:
Yes, Windows reserves space for a custom Long Value at the data of each item. Accessing them is easy with some API.

Code: Select all

Procedure SetItemLong(Gadget.l, Item.l, Value.l)
  Protected pitem.LV_ITEM
  pitem\mask = #LVIF_PARAM
  pitem\iItem = Item.l
  pitem\lParam = Value
  SendMessage_(GadgetID(Gadget), #LVM_SETITEM, 0, @pitem)
EndProcedure

Procedure.l GetItemLong(Gadget.l, Item.l)
  Protected pitem.LV_ITEM
  pitem\mask = #LVIF_PARAM
  pitem\iItem = Item.l 
  SendMessage_(GadgetID(Gadget), #LVM_GETITEM, 0, @pitem)
  ProcedureReturn pitem\lParam
EndProcedure
I did not test them, but it is such a simple code, it should work fine.

Timo
quidquid Latine dictum sit altum videtur
ebs
Enthusiast
Enthusiast
Posts: 562
Joined: Fri Apr 25, 2003 11:08 pm

Post by ebs »

Timo,

I tried your flags for the ListView, but they eliminate both scrollbars completely. I looked at the MSDN information, but I didn't see any way to remove just the horizontal scrollbar. Anything else you can suggest??

Eric
freak
PureBasic Team
PureBasic Team
Posts: 5948
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

I also didn't find any Infos on removing one Scrollbar only.
I gave the thing with #WS_VSCROLL a try, and it worked here, but maybe
it doesn't work on all systems.

Meybe there is no way for that then, sorry

Timo
quidquid Latine dictum sit altum videtur
ebs
Enthusiast
Enthusiast
Posts: 562
Joined: Fri Apr 25, 2003 11:08 pm

Post by ebs »

Just for my information, what OS are you using? I have Win XP Home.
freak
PureBasic Team
PureBasic Team
Posts: 5948
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

Win2k Sp3

But more important is the Version of IE here, because updates of the
common control's dlls usually come with IE.

I use IE5, because IE6 had some problems with my proxy settings.

Timo
quidquid Latine dictum sit altum videtur
ebs
Enthusiast
Enthusiast
Posts: 562
Joined: Fri Apr 25, 2003 11:08 pm

Post by ebs »

Timo,

I figured it out! It's a lot simpler than I thought, and doesn't seem to have anything to do with the OS or IE. It seems that there must be enough space to display the vertical scrollbar without overlapping the last (or only) column in the list.

Specifically, I set the gadget width to 110 and the first (only) column width to 90, leaving 20 pixels for the scrollbar. This displays a horizontal scrollbar when the vertical one is displayed. When I decrease the column width to 89, I get only the vertical scrollbar, which is exactly what I want!

The only unfortunate part of this is the unnecessary vertical line in the column header, but I don't want to be too picky! :)

Thanks for plodding through this with me.

Eric
ebs
Enthusiast
Enthusiast
Posts: 562
Joined: Fri Apr 25, 2003 11:08 pm

Post by ebs »

Timo (or anyone else who can help),

You've been very helpful with all my questions so far, how about YAQ:

Do you know of a way to get a PureBasic event when clicking on the column header of a ListIconGadget? I've experimented with a couple of the Extended ListView Style flags, but I haven't found anything yet. If it would work with a callback routine, that would be OK.

Thanks,
Eric
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

--Kale

Image
ebs
Enthusiast
Enthusiast
Posts: 562
Joined: Fri Apr 25, 2003 11:08 pm

Post by ebs »

Kale,

Thanks for the pointer. I copied Justin's code and will try it out.

Eric
User avatar
Techie42
User
User
Posts: 58
Joined: Sun Oct 30, 2005 12:28 pm
Location: UK (Berkshire)

Post by Techie42 »

freak wrote:About the LONG Values:
Yes, Windows reserves space for a custom Long Value at the data of each item. Accessing them is easy with some API.

Code: Select all

Procedure SetItemLong(Gadget.l, Item.l, Value.l)
  Protected pitem.LV_ITEM
  pitem\mask = #LVIF_PARAM
  pitem\iItem = Item.l
  pitem\lParam = Value
  SendMessage_(GadgetID(Gadget), #LVM_SETITEM, 0, @pitem)
EndProcedure

Procedure.l GetItemLong(Gadget.l, Item.l)
  Protected pitem.LV_ITEM
  pitem\mask = #LVIF_PARAM
  pitem\iItem = Item.l 
  SendMessage_(GadgetID(Gadget), #LVM_GETITEM, 0, @pitem)
  ProcedureReturn pitem\lParam
EndProcedure
I did not test them, but it is such a simple code, it should work fine.

Timo
FYI...when items are sorted, the lParam value is used, and so if you change this value then you change the inherent sort sequence.

For example, if you had a list of 10 items, and you changed the odd numbered items to contain "5" in the lParam field, and changed the even numbered items to contain "8", then those containing "5" in lParam would be grouped before those containing "8".

I found this out to my cost...I could not understand why my custom redrawing was going strange...until I discovered that the lParam was being autofilled by the sort routines :cry:

Thanks.
If the temperature today was 0 degrees, how can it be twice as cold tomorrow?
Post Reply