请问,怎样才能使 listbox 的每个item 附带一个其它数据(如:某个类型的指针),就象 treeview 的treenode 有个data 属性。急,多谢了

MarsChen 2001-09-07 10:55:39
请问,怎样才能使 listbox 的每个item 附带一个其它数据(如:某个类型的指针),就象 treeview 的treenode 有个data 属性
...全文
215 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
luhongjun 2001-09-07
  • 打赏
  • 举报
回复
不错。
火鸟33 2001-09-07
  • 打赏
  • 举报
回复


我用两个一样的控件一起用的,就是太麻烦
MarsChen 2001-09-07
  • 打赏
  • 举报
回复
items->count到底是怎么记数的?为什么我仅仅用
items->addobject("a",(tobject*)p);添加了一个项目
而items->count却=2?
HEROIN 2001-09-07
  • 打赏
  • 举报
回复
listbox->Item->AddObject("编辑框", (System::TObject*)Edit1);
wangledong 2001-09-07
  • 打赏
  • 举报
回复
这是BCB自带的例子,你看看吧!
This example requires a TListView, a TImageList and a TComboBox. You will need to double click the image list and add several images to the image list prior to running the project. You can use *.bmp or *.ico files from the \Images\Icons directory.
During the form抯 OnCreate event handler, items for the List View control are created for each image in the Image List and the ImageIndex is assigned the number of the image within the ImageList. Two columns are created so that when ViewStyle is vsReport, you will have columns to view.

Also within the form抯 OnCreate event handler assign the ComboBox each of the four TViewStyle constants to the Items?Objects property. You could also simply code this within a series of OnClick event handlers as, for instance, ListView1->ViewStyle = vsIcon.

void __fastcall TForm1::FormCreate(TObject *Sender)

{
TListItem *pItem;
TListColumn *pColumn;
// Create a ListView item for each image in the ImageList
ListView1->SmallImages = ImageList1;
ListView1->LargeImages = ImageList1;
for (int i = 0; i < ImageList1->Count; i++)
{
pItem = ListView1->Items->Add();
pItem->Caption = "Image" + IntToStr(i);
pItem->ImageIndex = i;
}
// Create two columns to show during viewing as vsReport

pColumn = ListView1->Columns->Add();
pColumn->Caption = "Column 1";
pColumn = ListView1->Columns->Add();
pColumn->Caption = "Column 2";
// Add View styles and constants to the Combo Box
ComboBox1->Items->AddObject("vsIcon", (TObject *)vsIcon);
ComboBox1->Items->AddObject("vsList", (TObject *)vsList);
ComboBox1->Items->AddObject("vsReport", (TObject *)vsReport);
ComboBox1->Items->AddObject("vsSmallIcon", (TObject *)vsSmallIcon);

// Display first item in the Combo Box
ComboBox1->ItemIndex = 0;
}

void __fastcall TForm1::ComboBox1Click(TObject *Sender)

{
ListView1->ViewStyle = (TViewStyle) ComboBox1->Items->Objects[ComboBox1->ItemIndex];
}
MarsChen 2001-09-07
  • 打赏
  • 举报
回复
能写个例子么?多谢了
wangledong 2001-09-07
  • 打赏
  • 举报
回复
Strings有个AddObject方法,就可以了!
MarsChen 2001-09-07
  • 打赏
  • 举报
回复
散分了
MarsChen 2001-09-07
  • 打赏
  • 举报
回复
什么不错?告我怎么回事啊

13,873

社区成员

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

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