HOME   DOWNLOADS   ORDER ONLINE   CONTACT US



 OVERVIEW
 
 DOWNLOAD
 
 ORDER ONLINE
 
 KNOWLEDGE
 BASE

How to use the AddPacket method

The AddPacket method was borne out of laziness, and simply provides a code-efficient way of adding a list item. The two code samples below both achieve the same result:

SBList1.AddItem "Hi!"
SBList1.ItemText(SBList1.NewIndex) = "XYZ"
SBList1.ItemData(SBList1.NewIndex) = 123
SBList1.ItemPicture(SBList1.NewIndex) = Pic1.Picture
SBList1.ItemBackColor(SBList1.NewIndex) = QBColor(12)
is the same as:

SBList1.AddPacket -1, "Hi!", "XYZ", 123, _
    Pic1.Picture, QBColor(12)
In short, AddPacket saves you having to reference the most recent list item (NewIndex) when you want to set the most commonly used item values. The first three parameters of AddPacket are the minimum requirement; after all, if you only want to set the list text and position you might as well just use AddItem. An easy mistake to make is to accidentally omit the ItemText value (the third value in the sequence) when you are specifying the picture value. For example:

SBList1.AddPacket -1, "Hi!", , , Pic1.Image
will generate an "Argument not optional" error message at design time. The correct syntax is:

SBList1.AddPacket -1, "Hi!", "", , Pic1.Image
You can also use indirect references in place of standard references for the Picture element of AddPacket. For example:

SBList1.AddPacket -1, "Hi!", "XYZ", 123, _
   imagelist1.ListImages(5)
However, you cannot link an ImageList control to an SBList in the same way as you can with the Microsoft TreeView control, for example. You must use an indirect reference as shown above.

Topic devised by Andy Groom.

 
Copyright © 2000 Global Components. All rights reserved.