领悟旧事

Learned Helplessness
分类新闻>>技术文章>>
对ListBox或FileListBox进行排序的代码
来源:http://www.xx0594.com/
时间:2017-9-11
作者:  浏览人数:1159
void __fastcall TForm1::ListBoxSort(TFileListBox *lb)
{
   if ( lb->Items->Count > 1 )
   {
   bool swapped;
   do
   {
   int counter = lb->Items->Count - 1;
   swapped = false;
   while ( counter - 1 > 0 )
   {

      // Compare the items' length.
      if ( lb->Items->Strings[ counter ].Length() < lb->Items->Strings[ counter - 1 ].Length() )
      {

      // Swap the items.
      AnsiString temp = lb->Items->Strings[ counter ];
      lb->Items->Strings[ counter ] = lb->Items->Strings[ counter - 1 ];
      lb->Items->Strings[ counter - 1 ] = temp;
      swapped = true;
      }

      // Decrement the counter.
      counter -= 1;
   }
   }
   while ( (swapped == true) );
   }
}
//---------------------------------------------------------------------------
//调用未例
void __fastcall TForm1::FileListBox1Change(TObject *Sender)
{
 ListBoxSort(FileListBox1);
}
//---------------------------------------------------------------------------

关闭窗口
 访问量:507982
任何第三方若要引用、转摘本站信息,均需征得本站书面同意,否则视为侵权。本站信息为个人观点,若因引用本站信息而产生的任何情况,均与本站无关。Email:linmutou@163.com
闽ICP备14017840号-2