Clear ListView (firemonkey)

  

I’m building an FMX app for Windows that has a button and a TListView control. The button code is just a query of an SQLite db used to populate the TListView. Under some circumstances the query takes 5-10 seconds to process. I’d like to immediately clear the TListView when the button is clicked (before the query gets done and repopulates the list). At the first of the button code i have a call to the Clear method but it doesn’t work immediately:

ListView1->Clear();

The old data remains in the TListView control until after the query completes and refreshes it. How can i force the list to empty FIRST.

thanks,
russ

UPDATED to clearly show what is happening:

// This entire block of code below is inside a button click.
Form1->ListView1->Clear();
// This next line of code is what Frederico suggested – it works.
Application->ProcessMessages();

Form1->FDConnection1->Params->Values[“Database”] = “T:\\mydata.db”;
TFDQuery *query;
query = new TFDQuery(NULL);
query->Connection = Form1->FDConnection1; // SQLite db
query->SQL->Text = “SELECT DISTINCT Project FROM Engineer_Updates WHERE Employee = ‘” + Form1->lblEngineerInitials->Text + “‘ ORDER BY Project”;
query->Open();
while(!query->Eof) {
TListViewItem* itemHeader = Form1->ListView1->Items->Add();
Form1->ListView1->BeginUpdate();
itemHeader->Purpose = TListItemPurpose::Header;
itemHeader->Text = query->FieldByName(“Project”)->AsString; // + ” – ” + query->FieldByName(“Project WO”)->AsString; // “My Header”;
Form1->ListView1->EndUpdate();
TFDQuery *query2;
query2 = new TFDQuery(NULL);
try {
query2->Connection = Form1->FDConnection2; // SQLite db
query2->SQL->Text = “SELECT * FROM Engineer_Updates WHERE Project = ‘” + query->FieldByName(“Project”)->AsString + “‘ AND Employee = ‘” + Form1->lblEngineerInitials->Text + “‘”;
query2->Open();
while (!query2->Eof) {
TListViewItem* item2Add = Form1->ListView1->Items->Add();
Form1->ListView1->BeginUpdate();
item2Add->Text = query2->FieldByName(“Terminal/Equipment”)->AsString + “, ” + query2->FieldByName(“Activity”)->AsString;
mystring2 = query2->FieldByName(“Terminal/Equipment”)->AsString + “, ” + query2->FieldByName(“Activity”)->AsString;
item2Add->Detail = mystring2;
Form1->ListView1->EndUpdate();
query2->Next();
}
}
__finally {
query2->Close();
query2->DisposeOf();
}
query->Next();
}
query->Close();
query->DisposeOf();

Comments are closed.