在CB中如何使用TreeView和ListView?

forise 2000-08-21 09:42:00
我是菜鸟!如何使用?请给出例子。
谢谢了
...全文
192 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
skt642 2001-05-31
  • 打赏
  • 举报
回复
82599关注!
  • 打赏
  • 举报
回复
在 ListView 中加入一项
ListView 控件在IDE中提供了完整的用于增减项的接口。 但我们通常需要在运行时动态地加入若干项。 下面的代码演示了如何加入一个项或子项:

int NumEntries = 20;
TListItem *NewEntry;
ListView1->Items->BeginUpdate();
ListView1->Items->Clear();
for (int j=0; j < NumEntries; j++)
{
NewEntry = ListView1->Items->Add();
NewEntry->Caption = "Item " + IntToStr(j);
NewEntry->SubItems->Add("column 2");
NewEntry->SubItems->Add("column 3");
// NewEntry->ImageIndex = j; // 如果使用这一句的话会需要一个 imagelist
}
ListView1->Items->EndUpdate();

BeginUpdate 函数防止项目加入 ListView 时产生不必要的闪烁。 EndUpdate 调用则表明已经完成项的添加, 可以刷新了。
此外,尽量使用 TListItem 的 Add 函数, 而不要直接使用 new。


This example requires only a blank form. All other objects: TListView, TListColumns, TListItems, are created dynamically. You must add #include <comctrls.hpp> to the top of the unit file.

void __fastcall TForm1::FormCreate(TObject *Sender)

{
const char Names[6][2][10] =
{{"Rubble","Barny"},
{"Michael", "Johnson"},
{"Bunny", "Bugs"},
{"Silver", "HiHo"},
{"Simpson", "Bart"},
{"Squirrel", "Rocky"}};

TListColumn *NewColumn;
TListItem *ListItem;
TListView *ListView = new TListView(this);

ListView->Parent = this;
ListView->Align = alClient;
ListView->ViewStyle = vsReport;
NewColumn = ListView->Columns->Add();
NewColumn->Caption = "Last";

NewColumn = ListView->Columns->Add();
NewColumn->Caption = "First";
for (int i = 0; i < 6; i++)
{
ListItem = ListView->Items->Add();
ListItem->Caption = Names[i][0];
ListItem->SubItems->Add(Names[i][1]);
}
}
wxz 2000-08-21
  • 打赏
  • 举报
回复
cb有这样的例程,建议你到http://coobe.cs.hn.cninfo.net/~cbstep下载cb源程序"图标狩猎者"看看

13,822

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧