0 J$ r1 D) ]" D5 O# C+ q. x Answer: The ListView control provides a nice interface for adding items at design time from the IDE. However, you will usually need to fill in the ListView based on runtime information. This code snippet shows how to create ListView items and subitems from code.
; e$ A! Q* ^ M0 B1 ?4 d% wint NumEntries = 20; TListItem *NewEntry; ListView1->Items->BeginUpdate(); ListView1->Items->Clear(); for (int j=0; j < NumEntries; j++)4 M3 w3 z6 P! W- x4 {' O- R { NewEntry = ListView1->Items->Add(); NewEntry->Caption = "Item " + IntToStr(j); NewEntry->SubItems->Add("column 2");7 u% [& n B$ k3 a& U& k NewEntry->SubItems->Add("column 3"); // NewEntry->ImageIndex = j; // requires an imagelist }/ s: o; e4 a5 v* |2 o ListView1->Items->EndUpdate();
Note: The BeginUpdate function prevents the ListView from flickering as the items are added. Both TListBox and TListView provide a BeginUpdate function that you can call to keep the control from flashing as you manipulate the control's contents. The EndUpdate call signals that you have finished altering the control and that the control should now paint itself.
Note: Notice that you obtain the TListItem pointer by calling the Add function, rather than calling new directly.
Note: Also notice that you change the characteristics of the new item after calling the Add function.
9 Z4 v/ |$ c% ?/ qNote: The Caption string appears next to the item's icon, and will always appear regardless of the ViewStyle setting of the ListView. The SubItems appear in separate columns when ViewStyle is set to vsReport. For other modes, the SubItems are invisible.
| 欢迎光临 数学建模社区-数学中国 (http://www.madio.net/) | Powered by Discuz! X2.5 |