一个listview循环插入单元格数据的思路,求解决
我现在有一行数据,unsigned char senddata[11]={0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x10,0x11}; 有一个listview,每行只有4列,我想把senddata中的数据插入到listview中,插入后的效果如下:
listview:
列1 列2 列3 列4
01 02 03 04
05 06 07 08
09 10 11
请问该如何来写这个程序呢????
[解决办法]
void __fastcall TForm1::btn2Click(TObject *Sender)
{
unsigned char senddata[11]={0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x10,0x11};
TListItem *pListItem1;
TListColumn *pListItem;
int i;
ListView1->Columns->Clear();
ListView1->Clear();
ListView1->ViewStyle = vsReport;
pListItem = ListView1->Columns->Add();
pListItem->Caption = "C1";
pListItem = ListView1->Columns->Add();
pListItem->Caption = "C2";
pListItem = ListView1->Columns->Add();
pListItem->Caption = "C3";
pListItem = ListView1->Columns->Add();
pListItem->Caption = "C4";
for(i=0;i<11;i++)
{
pListItem1 = ListView1->Items->Add();
pListItem1->Caption = IntToHex(senddata[i++],2);
if(i>=11 )
break;
pListItem1->SubItems->Add( IntToHex(senddata[i++],2) );
if(i>=11 )
break;
pListItem1->SubItems->Add( IntToHex(senddata[i++],2));
if(i>=11 )
break;
pListItem1->SubItems->Add( IntToHex(senddata[i++],2) );
}
}