type TForm1 = class(TForm) ... private ListEdit : TEdit; procedure ListEditKeyPress(Sender: TObject; var Key: Char) ; end;
//create the TEdit and make ListBox its parent procedure TForm1.FormCreate(Sender: TObject) ; begin ListEdit := TEdit.Create(self) ; ListEdit.Visible := false; ListEdit.Ctl3D := false; ListEdit.BorderStyle := bsNone; ListEdit.Parent := ListBox1; ListEdit.Width := ListBox1.ClientWidth; ListEdit.OnKeyPress := ListEditKeyPress; end;
//ListView Item selected - position the Edit procedure TForm1.ListBox1Click(Sender: TObject) ; var ii : integer; lRect: TRect; begin ii := ListBox1.ItemIndex; if ii = -1 then exit;
//apply editing when enter key is pressed procedure TForm1.ListEditKeyPress(Sender: TObject; var Key: Char) ; var ii: Integer; begin if Key = #13 then begin ii := ListBox1.ItemIndex; ListBox1.Items.Delete(ii) ; ListBox1.Items.Insert(ii, ListEdit.Text) ; ListEdit.Visible := False; Key := #0; end; end;
//hide Edit when ListBox looses the focus procedure TForm1.ListBox1Exit(Sender: TObject) ; begin ListEdit.Visible := false; end;