marinedestroyer2
asked on
listbox action
I would like to know how to read every line from a listbox and then doing something. For example, the listbox has the full path names of files...and then the user clicks a button and these files in the listbox is deleted.
Hello
if you want to delete every file in the list box by click on it, just add this code in onclick event
procedure TForm1.ListBox1Click(Sende r: TObject);
begin
DeleteFile(ListBox1.Items. Strings[Li stBox1.Ite mIndex]);
end;
but if you want to select some items then to delete them i on click, set the MulitSelect for Listbox to true, and add button and write this code
procedure TForm1.Button1Click(Sender : TObject);
var
I : integer;
begin
for I := 0 to ListBox1.Items.Count -1 do
if ListBox1.Selected[I] then
DeleteFile(ListBox1.Items. Strings[I] );
end;
Mohammed
if you want to delete every file in the list box by click on it, just add this code in onclick event
procedure TForm1.ListBox1Click(Sende
begin
DeleteFile(ListBox1.Items.
end;
but if you want to select some items then to delete them i on click, set the MulitSelect for Listbox to true, and add button and write this code
procedure TForm1.Button1Click(Sender
var
I : integer;
begin
for I := 0 to ListBox1.Items.Count -1 do
if ListBox1.Selected[I] then
DeleteFile(ListBox1.Items.
end;
Mohammed
hi , marinedestroyer2
i had written your answer at the end of your last question.
hamed
i had written your answer at the end of your last question.
hamed
if it is related your last question!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Accept alanwhincup's comment as answer
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
Thank you,
Russell
EE Cleanup Volunteer
I will leave a recommendation in the Cleanup topic area that this question is:
Accept alanwhincup's comment as answer
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
Thank you,
Russell
EE Cleanup Volunteer
To use it just put a ListBox and Button component on a form and put the following code under the Button's OnClick event.
procedure TForm1.Button1Click(Sender
var
I : Integer;
begin
if ListBox1.Items.Count > 0 then
begin
for I := 0 to ListBox1.Items.Count - 1 do
begin
if FileExists(ListBox1.Items[
DeleteFile(ListBox1.Items[
else
ShowMessage('File does not exist.');
end;
end
else
ShowMessage('No files listed.');
end;
Cheers,
Alan