Board index » cppbuilder » Virtual Listview and loading from a DB
Greg Stantin
![]() CBuilder Developer |
Virtual Listview and loading from a DB2003-08-25 04:47:57 AM cppbuilder57 What little i learned the other day about the virtual listview i am trying to to implement today. The examples that i had seen with a virtual listview all had to do with loading your info into some sort of list, them passing it to the listview. Is it not possible to add the items directly to the listview from a db without using a list and a struct? If i go thought the db and count the records, then go through the db again, that is doing the same process twice. How can i grab the info directly from the db and insert it directly into the listview? I have 5 fields that i want to grab from each record of the db and place it into the listview, but i really don't want to have to do something like this to get it done. //-------------------------------------------------------- struct TTestInfo { AnsiString Field1; AnsiString Field2; AnsiString Field3; AnsiString Field4; AnsiString Field5; }; TList* aList; //-------------------------------------------------------- aList = new TList; //-------------------------------------------------------- int TableCount = 0; while(!Table1->Eof) { TTestInfo* ti = new TTestInfo; ti->Field1 = Table1->FieldByName("Field1")->AsString; ti->Field2 = Table1->FieldByName("Field2")->AsString; ti->Field3 = Table1->FieldByName("Field3")->AsString; ti->Field4 = Table1->FieldByName("Field4")->AsString; ti->Field5 = Table1->FieldByName("Field5")->AsString; ++TableCount; aList->Add(ti); } ListView1->Items->Count = TableCount; //-------------------------------------------------------- void __fastcall TForm1::ListView1Data(TObject *Sender, TListItem *Item) { TTestInfo* ti = (TTestInfo*)aList->Items[Item->Index]; // Set the Caption and ImageIndex properties. Item->Caption = ti->Field1; Item->SubItems->Add(ti->Field2); Item->SubItems->Add(ti->Field3); Item->SubItems->Add(ti->Field4); Item->SubItems->Add(ti->Field5); } //-------------------------------------------------------- Can someone elaborate on this topic so i can understand it a bit more, these records are in the thousands and i would like effiency when loading them. Thanks. |