• Breaking News

    Panduan dan Tutorial Lengkap serta Materi Pelajaran di Mulyono Blog. Konten Terlengkap dan Terpercaya

    Selasa, 20 September 2011

    Memindahkan Item pada list Box

    unit Unit1;

    interface

    uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, StdCtrls, Buttons;

    type
    TForm1 = class(TForm)
    ListBox1: TListBox;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    private
    { Private declarations }
    public
    { Public declarations }
    end;

    var
    Form1: TForm1;

    implementation

    {$R *.dfm}

    procedure TForm1.BitBtn1Click(Sender: TObject);
    var
    CurrIndex: Integer;
    begin
    if ListBox1.ItemIndex > 0 then
    begin
    CurrIndex := ListBox1.ItemIndex;
    ListBox1.Items.Move(ListBox1.ItemIndex, (CurrIndex - 1));
    ListBox1.ItemIndex := CurrIndex - 1;
    end;
    end;

    procedure TForm1.BitBtn2Click(Sender: TObject);
    var
    CurrIndex, LastIndex: Integer;
    begin
    CurrIndex := ListBox1.ItemIndex;
    lastindex := ListBox1.Items.Count;

    if ListBox1.ItemIndex <> -1 then
    begin
    if CurrIndex + 1 < lastindex then
    begin
    ListBox1.Items.Move(ListBox1.ItemIndex, (CurrIndex + 1));
    ListBox1.ItemIndex := CurrIndex + 1;
    end;
    end;
    end;

    end.