Important: The information in this document is obsolete and should not be used for new development.
Adding Rows and Columns to a List
Your application can choose to preallocate the cells it needs when it creates a list. For example, an application might preallocate the columns it needs, and then add rows to the list one by one. Other applications might create a list and add both rows and columns to it later. Regardless of the technique your application uses to create its cells, it can set the data in a cell by using theLSetCellprocedure.You specify the data, the length of the data, the location of the cell whose data you wish to set, and a handle to the list containing the cell, as parameters to the
LSetCellprocedure. Listing 4-4 demonstrates an application-defined procedure that adds rows to a one-column list based on the contents of a string list resource. TheMyAddItemsFromStringListprocedure adds each row to the list using theLAddRowfunction, then sets the data of the cell in the first (and only) column of the newly added row using theLSetCellprocedure.Listing 4-4 Adding items from a string list to a one-column, text-only list
PROCEDURE MyAddItemsFromStringList (myList: ListHandle; stringListID: Integer); VAR index: Integer; {index within string list} rowNum: Integer; {row number to add string to} myString: Str255; {string to add} aCell: Cell; {cell to store string in} BEGIN {compute new row number} rowNum := myList^^.dataBounds.bottom; index := 1; {start with first string} REPEAT GetIndString(myString, stringListID, index); IF myString <> '' THEN BEGIN {add new row for string} {specify #rows to add, row number of first new row} rowNum := LAddRow(1, rowNum, myList); {prepare to set cell data--specify } { the cell's column number, row number} SetPt(aCell, 0, rowNum); {set cell data to string} LSetCell(@myString[1], Length(myString), aCell, myList); END; rowNum := rowNum + 1; index := index + 1; UNTIL myString = ''; END;TheMyAddItemsFromStringListprocedure defined in Listing 4-4 adds strings from a string list resource to the end of a list. It keeps track of the index of the string in the string list with theindexvariable, and it tracks the number of the new row to add in therowNumvariable.The
MyAddItemsFromStringListprocedure adds a new row by calling theLAddRowfunction. The first parameter toLAddRowspecifies the number of rows to add, and the second parameter specifies the row number of the first new row.LAddRowreturns the row number of the first row added, which differs from the second parameter only if that parameter specifies a row number that is out of range.After creating a new row,
MyAddItemsFromStringListsets the cell in the first column of the added row to the text contained within the string. Note that the procedure does not copy the length byte of the string.To add columns to a list, your application can use the
LAddColumnfunction, which works just likeLAddRow.To delete a row or column from a list, your application can call the
LDelRowprocedure or theLDelColumnprocedure. The first parameter of each of these procedures is
the number of rows (or columns) to delete, and the second parameter is the row or column number of the first to be deleted. For example, this code deletes the first row
of a list:
LDelRow(1, 0, myList);{#rows to delete, starting row number}When making many changes to a list, your application should temporarily disable the automatic drawing mode (unless the list is in a window that is not yet visible). To do so, call theLSetDrawingModeprocedure to turn off the automatic drawing mode, make the changes to the list, turn the automatic drawing mode back on, and redraw the list (by invalidating a rectangle containing the list and its scroll bars and later calling theLUpdateprocedure when your application receives an update event). You might do these steps as follows:
LSetDrawingMode (FALSE, myList); {...(make changes to the list)...} LSetDrawingMode (TRUE, myList); InvalRect(myList^^.rView); IF (myList^^.vScroll <> NIL) THEN InvalRect(myList^^.vScroll^^.contrlRect); IF (myList^^.hScroll <> NIL) THEN InvalRect(myList^^.hScroll^^.contrlRect);
 
  
  
 