was ist neu ¦  programmier tips ¦  indy artikel ¦  intraweb artikel ¦  informationen ¦  links ¦  interviews
 sonstiges ¦  tutorials ¦  Add&Win Gewinnspiel

Tips (1541)

Dateien (137)
Datenbanken (90)
Drucken (35)
Grafik (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Mathematik (76)
Multimedia (45)
Oberfläche (107)
Objekte/
ActiveX (51)

OpenTools API (3)
Sonstiges (126)
Strings (83)
System (266)
VCL (242)

Tips sortiert nach
Komponente


Tip suchen

Tip hinzufügen

Add&Win Gewinnspiel

Werbung

49 Visitors Online


 
...eine Listbox editierbar machen?
Autor: Damian Gorski
[ Tip ausdrucken ]  

Tip Bewertung (7):  
     


{NOTE : This will also work with an OwnerDraw ListBox
But be sure you "pad" the Left Property of the Edit so
Any icons etc, do not get covered up by the TEdit.
And also be aware that there will be a bit of "flashing"
if you do use an OwnerDraw ListBox}

{This is in a Popup menu.}
procedure TForm1.Change1Click(Sender: TObject);
var
  
I9: Integer;
  ColInt: Integer;
  LRect: TRect;
begin
  
LRect := ListBox1.ItemRect(ListBox1.ItemIndex);
  {Set the size of the TEdit}
  
Edit1.Top := LRect.Top + 1;
  Edit1.Left := LRect.Left + 1;
  Edit1.Width := ListBox1.Canvas.TextWidth(ListBox1.Items.Strings[ListBox1.ItemIndex]) + 6;
  Edit1.Height := (LRect.Bottom - LRect.Top) + 1;

  Edit1.Text := ListBox1.Items.Strings[ListBox1.ItemIndex];
  ListBox1.Selected[ListBox1.ItemIndex] := False;
  Edit1.Visible := True;
  Edit1.SelectAll;
  Edit1.SetFocus;
end;

procedure TForm1.ListBox1Click(Sender: TObject);
begin
  
Edit1.Visible := False;
end;

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
var
  
I8: Integer;
begin
  if 
Key = #13 then
  begin
    
I8 := ListBox1.ItemIndex;
    ListBox1.Items.Delete(ListBox1.ItemIndex);
    ListBox1.Items.Insert(I8, Edit1.Text);
    Edit1.Visible := False;
    Key := #0;
  end;
end;

 

Bewerten Sie diesen Tipp:

dürftig
ausgezeichnet


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners