TListView问题
以为自己对这个控件有所了解了,今儿个随意测试了个玩意,居然出了问题,百思不得其解,汗颜之,特发出来请大家给与指点。
程序思路如下,表格共有10列,放个定时器每秒钟横向填入一个数字,直至该行填完,然后再增加一行,如此循环:
void TfrmTest::tmr1Timer(TObject *Sender){ int Row = lv->Items->Count-1; TListItem* Item = lv->Items->operator [](Row); if( NULL == Item ) { Item = lv->Items->Add(); Item->Caption = "0"; } else { int nCount = Item->SubItems->Count; if( nCount >= 10 ) { Item = lv->Items->Add(); Item->Caption = "0"; } } Item->SubItems->Add("1");//问题产生的行, ERROR:List Index out of bounds.}
void __fastcall TForm1::Timer1Timer(TObject *Sender){ static int i = 0; TListItem *li; if (lv->Items->Count > 0) { li = lv->Items->Item[lv->Items->Count - 1]; } else { li = lv->Items->Add(); li->Caption = i++; return; } if (li->SubItems->Count >= 9) { li = lv->Items->Add(); li->Caption = i++; } else li->SubItems->Add(i++);}