TListView的OnData事件什么时候触发啊?怎么用的啊?

kissfire 2003-07-14 07:52:40
比如,我的数据在TList中,我不想循环插入,怎样做?
...全文
300 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
zihan 2003-07-15
  • 打赏
  • 举报
回复
还有就是数据存放在了MResultList5这个里面,PRV是一个指向这个数据类型的指针
zihan 2003-07-15
  • 打赏
  • 举报
回复
不好意思,上面的那个Edit2.Text是指的ListView的列数,
zihan 2003-07-15
  • 打赏
  • 举报
回复
给你一个例子把
是delphi的,你自己把它改写成cb的吧,差不多

还有就是你在添加之前,只需要设定这个list的数量如 ListView2.Items.Count = PRV.Count然后刷新她就可以了
其PRV是一个存放数据的TList类型的东东
procedure TMainForm.ListView2Data(Sender: TObject; Item: TListItem);
var
I: Integer;
begin
PRV := MResultList5.Items[Item.Index];
Item.Caption := IntToStr(PRV^[1]);
for I := 2 to StrToInt(Edit2.Text) do
Item.SubItems.Add(IntToStr(PRV^[I]));
end;
「已注销」 2003-07-15
  • 打赏
  • 举报
回复
学习学习
Friecin 2003-07-14
  • 打赏
  • 举报
回复
采用常规方法处理ListView,在数据量大时无论是还是用了BeginUpdata和EndUpdata()还是处理WM_EraseBkgnd信息都不会得到理想的效果,那答案是什么呢?
嗯,采用所谓Virtual ListView。

在于把ListView->OwnerData设为true,然后直接设置
ListView->Items->Count为数据总数,实际的数据可以保在任意其它速度较快且可直接索引的容器里(如STL中的vector),然后关键是在OnData事件中写入代码通过Item->Index从容器中(如vector)取出数据,然后用
Item->Caption = ???;
Item->SubItems->Add(???);
Item->SubItems->Add(???);
来动态的写入数据到ListView用于UI显示,如此Virtual ListView即完成.

一个完整的简单例子如下:
/*Unit1.h*/
//---------------------------------------------------------------------------

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ComCtrls.hpp>
#include <vector>
using namespace std;
//---------------------------------------------------------------------------
struct ListViewData
{
AnsiString Caption;
AnsiString SubItems1;
AnsiString SubItems2;
AnsiString SubItems3;
};
class TForm1 : public TForm
{
__published: // IDE-managed Components
TListView *ListView1;
void __fastcall ListView1Data(TObject *Sender, TListItem *Item);
private: // User declarations
vector<ListViewData*> m_lvDataVector;
public: // User declarations
__fastcall TForm1(TComponent* Owner);
__fastcall ~TForm1();
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif

/*unit1.cpp*/
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
ListView1->OwnerData = true;
const int iListViewCount = 5000;
ListView1->Items->Count = iListViewCount;
for(int i = 0; i < iListViewCount; ++i) {
ListViewData *plvData = new ListViewData;
plvData->Caption = "Caption" + AnsiString(i);
plvData->SubItems1 = "SubItems1" + AnsiString(i);
plvData->SubItems2 = "SubItems2" + AnsiString(i);
plvData->SubItems3 = "SubItems3" + AnsiString(i);
m_lvDataVector.push_back(plvData);
}
}

__fastcall TForm1::~TForm1()
{
int iCount = ListView1->Items->Count;
for(int i = 0; i < iCount; ++i) {
ListViewData *plvData = m_lvDataVector[i];
delete plvData;
}
}
//---------------------------------------------------------------------------

void __fastcall TForm1::ListView1Data(TObject *Sender, TListItem *Item)
{
ListViewData *plvData = m_lvDataVector[Item->Index];
Item->Caption = plvData->Caption;
Item->SubItems->Add(plvData->SubItems1);
Item->SubItems->Add(plvData->SubItems2);
Item->SubItems->Add(plvData->SubItems3);
}
//---------------------------------------------------------------------------
teatool 2003-07-14
  • 打赏
  • 举报
回复
Faq里有
kissfire 2003-07-14
  • 打赏
  • 举报
回复
不会这样敷衍我吧?例子呢?
ybluo 2003-07-14
  • 打赏
  • 举报
回复
Use OnData to customize an item before it is displayed in the list view control. Set the properties of the list item in the event handler so that they appear correctly when the item is drawn.

OnData occurs only if OwnerData is true.

13,826

社区成员

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

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