RAD Studio VCL Reference
|
Changes the position of a string in the list.
procedure Move(CurIndex: Integer; NewIndex: Integer); override;
virtual __fastcall Move(int CurIndex, int NewIndex);
Use Move to move the string at position CurIndex so that it occupies the position NewIndex. The positions are specified as 0-based indexes. For example, the following lines of code move the string in the first position to the last position.
MyStringsObject.Move(0, MyStringsObject.Count
MyStringsObject->Move(0, MyStringsObject->Count - 1);
If the string has an associated object, the object remains associated with the string in its new position.
C++ Examples:
/* This example uses a list box and a button on a form. The list box contains items when the form appears. When the user selects an item and clicks the button, the selected item in the list box is moved to the top of the list box: */ void __fastcall TForm1::FormCreate(TObject *Sender) { ListBox1->MultiSelect = false; Button1->Caption = "Move to Top"; for (int i = 1; i <= 10; i++) ListBox1->Items->Add("Item " + IntToStr(i)); } void __fastcall TForm1::Button1Click(TObject *Sender) { if (ListBox1->ItemIndex >= 0 && ListBox1->ItemIndex <= 9) ListBox1->Items->Move(ListBox1->ItemIndex, 0); }
Delphi Examples:
{ This example uses a list box and a button on a form. The list box contains items when the form appears. When the user clicks the button, the selected item in the list box is moved to the top of the list box: } procedure TForm1.Button1Click(Sender: TObject); begin if (ListBox1.ItemIndex in [0..9]) then ListBox1.Items.Move(ListBox1.ItemIndex, 0); end; procedure TForm1.FormCreate(Sender: TObject); var I: Integer; begin ListBox1.MultiSelect := False; Button1.Caption := 'Move to Top'; for I := 1 to 10 do ListBox1.Items.Add('Item ' + IntToStr(I)); end;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|