Mega Code Archive

 
Categories / Delphi / VCL
 

Speed Up Inserts Into TListView

Title: Speed Up Inserts Into TListView Question: Have you ever wondered why the screen flickers when inserting lines into a TListView? Well, you should use the Items.BeginUpdate and Items.EndUpdate functions. These functions disallows the screen to be update when lines are inserted, thereby speeding up the process substantially. Answer: // In this example I have created a TListView // called ListView1 var ListItem : TListItem; i : integer; begin ListView1.Items.BeginUpdate; // Do not update screen try ListView1.Items.Clear; for i := 0 to 10000 do begin ListItem := ListView1.Items.Add; ListItem.Caption := IntToStr(i); end; finally ListView1.Items.EndUpdate; // Update screen end; end; // In this dumb example I fill a TListView with // 10000 numbers. You should try and run the example // without BeginUpdate and EndUpdate and see // the difference.