LbAddItem Function

Microchip Graphics Library

Microchip Graphics Library
LbAddItem Function
C
LISTITEM * LbAddItem(
    LISTBOX * pLb, 
    LISTITEM * pPrevItem, 
    XCHAR * pText, 
    void * pBitmap, 
    WORD status, 
    WORD data
);
Overview

This function allocates memory for the LISTITEM and adds it to the list box. The newly created LISTITEM will store the location of pText, pBitmap and other parameters describing the added item.

Input Parameters
Input Parameters 
Description 
LISTBOX * pLb 
The pointer to the list box object. 
LISTITEM * pPrevItem 
Pointer to the item after which a new item must be inserted, if this pointer is NULL, the item will be appended at the end of the items list. 
XCHAR * pText 
Pointer to the text that will be inserted. Text must persist in memory for as long as it is referenced by an item in the list box. 
void * pBitmap 
Pointer to the bitmap for the item. Bitmap must persist in memory for as long as it is referenced by the an item in the list box. 
WORD status 
This parameter specifies if the item being added will be selected or redrawn (LB_STS_SELECTED or LB_STS_REDRAW). Refer to LISTITEM structure for details. 
WORD data 
User assigned data associated with the item. 
Returns

Return a pointer to the item created, NULL if the operation was not successful.

Preconditions

none

Side Effects

none

Example
const XCHAR ItemList[] = "Line1n" "Line2n" "Line3n";

extern BITMAP_FLASH myIcon;
LISTBOX *pLb;
LISTITEM *pItem, *pItemList;
XCHAR *pTemp;  

// Assume that pLb is pointing to an existing list box in memory 
// that is empty (no list).

// Create the list of the list box

// Initialize this to NULL to indicate that items will be added 
// at the end of the list if the list exist on the list box or 
// start a new list if the list box is empty. 
pItem = NULL;               
pTemp = ItemList;
pItem = LbAddItem(pLb, pItem, pTemp, NULL, LB_STS_SELECTED, 1)
if(pItem == NULL)
    return 0;
LbSetBitmap(pItem, &myIcon);

// Adjust pTemp to point to the next line
while((unsigned XCHAR)*pTemp++ > (unsigned XCHAR)31);

// add the next item
pItem = LbAddItem(pLb, pItem, pTemp, NULL, 0, 2)
if(pItem == NULL)
    return 0;
LbSetBitmap(pItem, &myIcon);

// Adjust pTemp to point to the next line
while((unsigned XCHAR)*pTemp++ > (unsigned XCHAR)31);

// this time insert the next item after the first item on the list
pItem = LbGetItemList(pLb); 
pItem = LbAddItem(pLb, pItem, pTemp, NULL, 0, 3)
if(pItem == NULL)
    return 0;
LbSetBitmap(pItem, &myIcon);
Microchip Graphics Library Version 3.06.02 - October 15, 2012
Copyright © 2012 Microchip Technology, Inc.  All rights reserved