Swapping items in a ListView 

This example shows a quick way of swapping items in a ListView without any flickering. 

KEYWORDS: Items->Add, Items->Delete, BeginUpdate, EndUpdate 
 
 

//---------------------------------------------------------------------------
//in source... 

void __fastcall TForm1::SwapLVItems(int a, int b) 

   int New; 
   ListView1->Items->BeginUpdate(); 
   {
      ListView1->Items->Add(); 
      New = ListView1->Items->Count - 1; 
      ListView1->Items->Item[New] = ListView1->Items->Item[a]; 
      ListView1->Items->Item[a] =  ListView1->Items->Item[b]; 
      ListView1->Items->Item[b] = ListView1->Items->Item[New]; 
      ListView1->Items->Delete(New); 
   }
   ListView1->Items->EndUpdate();