LISTVIEW Attributes Example


Example:

 

 

INCLUDE

PLBEQU.INC

*

 

 

.Define the Objects Needed

.

 

 

lvExample

LISTVIEW

 

clrWhite

COLOR

 

clrBlue

COLOR

 

clrGray

COLOR

 

fntItalic

FONT

 

lblText

STATTEXT

 

cmdQuit

BUTTON

 

*

 

 

.Work Variables

.

 

 

Result

INTEGER

4

String

DIM

20

Index

FORM

5

Name

DIM

20

Phone

DIM

20

Toggle

FORM

"1"

RowColor

String

10

*

 

 

.Create some color objects

.

 

 

  

CREATE

clrWhite=*WHITE

 

CREATE

clrGray=211:211:211

 

CREATE

clrBlue=*Blue

*

 

 

.Create a font object

.

 

 

  

CREATE

fntItalic,"Courier New",Size=12,Italic

*

 

 

.Create the listview object

.

 

 

  

CREATE

lvExample=2:16:15:50,Appearance=$3D:

  

 

Border=$True,GridLine=$TRUE

*

 

 

.Create the stattext instructions

.

 

 

  

CREATE

lblText=17:18:20:50:

  

 

"Double click a name to toggle","SYSTEM(10)"

*

 

 

.Create two columns in the listview

.

 

 

  

lvExample.InsertColumn using "Names",140,0

  

lvExample.InsertColumn using "Phones",140,1

*

 

 

.Add an attribute column

.

 

 

  

lvExample.InsertAttrColumn USING 2

*

 

 

.Set the attribute colors

.

 

 

  

lvExample.InsertAttrColor using clrWhite,clrGray,clrBlue

*

 

 

.Set the attribute font

.

 

 

  

lvExample.InsertAttrFont using fntItalic

*

 

 

.Set the default row attributes

.

 

 

  

lvExample.insertAttrDefault USING ",1" // white background

*

 

 

.Add 10 rows of data alternating the background color

.

 

 

 

FOR

Index,1,10

  

MOVE

Index,String

  

SQUEEZE

String,String

  

PACK

Name with "Name",String

  

PACK

Phone with "Phone",String

.

 

 

 

lvExample.InsertItemEx using Name,99,*SubItem1=Phone:

 

 

*SubItem2=RowColor

*

 

 

.Toggle the row background color

.

 

 

  

DECR

Toggle

  

IF

(Toggle)

  

CLEAR

RowColor // switch to the default

  

ELSE

 

  

MOVE

",2",RowColor // switch to tan

  

ENDIF

 

.

 

 

 

REPEAT

 

*

 

 

.Make the listview and stattext visible

.

 

 

  

SETPROP

lvExample,Visible=$True

  

SETPROP

lblText,Visible=$True

*

 

 

.Catch the double-click event on the listview

.

 

 

  

EVENTREGISTER

lvExample,$DblClick,Select,Result=Result

*

 

 

.Create and activate the quit button

.

 

 

  

CREATE

cmdQuit=20:21:26:34,"Quit",Cancel

  

ACTIVATE

cmdQuit,Quit,Result

*

 

 

.Wait for an Event to Occur

.

 

 

  

LOOP

 

  

EVENTWAIT

 

  

REPEAT

 

*

 

 

.The ListView Was Clicked - Toggle the colors and font

.

 

 

SELECT

 

 

  

lvExample.GetAttributeColum giving Index

.

 

 

 

MATCH

"1,3,1",String // if white on blue

 

IF

EQUAL

 

IF

(((Result / 2) * 2) = Result)

 

CLEAR

String // restore to the default

 

ELSE

 

 

MOVE

",2",String // restore to tan

 

ENDIF

 

 

ELSE

 

 

MOVE

"1,3,1",String

 

ENDIF

 

.

 

 

 

lvExample.SetItemText using Result,String,Index

.

 

 

  

RETURN

 

*

 

 

.Quit Button Clicked

.

 

 

QUIT

 

 

  

STOP

 

 

This example creates three colors (white, tan, and blue) and a font (courier, italic, size 12). It then creates a listview with two columns. The program next adds an attribute column ( column number two) and assocates the three colors with the listview attributes. Color1 is white, color2 is tan, and color3 is blue. Next the program associates the courier italic font with the listview as font1. Finally, the list has the white color (1) defined as the default background color.

 

The program then inserts ten rows of data. As rows are inserted, the background color for the entire row is toggled between the default color1 (white) and color2 (tan). The listview and instruction text are made visible and a quit button is added.

 

When the user double-clicks on the name column of a row, the column foreground color is set to white (color1), the background color is set to blue (color3), and the font is changed to couier italic (font1) for the entire row. The attribute string is therefore (1,3,1). Double-clicking the selected name once more restores the row to the original color.

 

 



PL/B Language Reference