QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2486|回复: 0
打印 上一主题 下一主题

Add items to a ListView from code at runtime.

[复制链接]
字体大小: 正常 放大
韩冰        

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

跳转到指定楼层
1#
发表于 2005-1-26 12:20 |只看该作者 |倒序浏览
|招呼Ta 关注Ta

3 V# G; w7 v4 H- G- }$ u& J Answer: 0 {( _& L# N5 M6 S3 ZThe 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.

* m8 w% ^! C3 W) t& w

int NumEntries = 20;5 r7 L7 q2 s, p1 y/ P, ? TListItem *NewEntry; 0 v( n! p @2 u0 C ListView1->Items->BeginUpdate();6 Z: Z5 c# S! B1 y' V& x' F: h. t ListView1->Items->Clear();/ R- v% W+ N( b' q7 O for (int j=0; j < NumEntries; j++) 4 i1 F r' Y7 p0 M+ y( }; S { * Y/ c! K" [1 k" p [' ^ C NewEntry = ListView1->Items->Add();9 l4 k3 C% X; ^, h" g! @/ L NewEntry->Caption = "Item " + IntToStr(j); 6 U$ k0 y! R0 N1 @2 ~ \, @# v5 B( O NewEntry->SubItems->Add("column 2"); ' f- G/ G* I: \! B7 y NewEntry->SubItems->Add("column 3"); + m/ F) ~7 c( V1 {6 M // NewEntry->ImageIndex = j; // requires an imagelist/ T( a! ~" L2 P }: c1 o$ \6 N' Z: Z ListView1->Items->EndUpdate();

) B- g6 R# M7 K" v

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.

2 H/ {" o0 t9 i/ O9 Y. Y6 B: }

Note: Notice that you obtain the TListItem pointer by calling the Add function, rather than calling new directly.

( a( D5 u& \6 k8 H0 S" u1 ^

Note: Also notice that you change the characteristics of the new item after calling the Add function.

$ o/ N1 @0 C, [7 l) W8 A$ _; c( {6 ^: ?

Note: 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. & ^$ [% U" t% y1 P1 A, X# W& Q

zan
转播转播0 分享淘帖0 分享分享0 收藏收藏0 支持支持0 反对反对0 微信微信
您需要登录后才可以回帖 登录 | 注册地址

qq
收缩
  • 电话咨询

  • 04714969085
fastpost

关于我们| 联系我们| 诚征英才| 对外合作| 产品服务| QQ

手机版|Archiver| |繁體中文 手机客户端  

蒙公网安备 15010502000194号

Powered by Discuz! X2.5   © 2001-2013 数学建模网-数学中国 ( 蒙ICP备14002410号-3 蒙BBS备-0002号 )     论坛法律顾问:王兆丰

GMT+8, 2026-4-18 12:07 , Processed in 0.373518 second(s), 52 queries .

回顶部