aztec
asked on
Using MultiSelect in ListBox
I've got a FileListBox and a regular ListBox. I've got MultiSelect set to true in the FileListBox. I simply want to be able to select multiple files from the FileListBox and when I click the RIGHT mouse button, have those files go into my ListBox. I've got the right mouse button click event thing figured out, but when I select multiple files from my FileListBox and perform the action, all I get in my ListBox is the last file selected, not all of them like I want. Here's my code so far:
procedure TForm1.FileListBox1MouseDo wn(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if Button = mbRight then
begin
ListBox1.Items.Add(FileLis tBox1.File Name);
end;
end;
.. So how can I add ALL the filenames I select to my ListBox, not just the last one of the bunch selected? What am I missing here?
Thanks,
Shawn Halfpenny
drumme59@sprint.ca
procedure TForm1.FileListBox1MouseDo
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if Button = mbRight then
begin
ListBox1.Items.Add(FileLis
end;
end;
.. So how can I add ALL the filenames I select to my ListBox, not just the last one of the bunch selected? What am I missing here?
Thanks,
Shawn Halfpenny
drumme59@sprint.ca
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Quite simple if you want the full path - this is what you do :
ListBox1.Items.Add(FileLis tBox1.Dire ctory+File ListBox1.I tems[i])
If you add the directory property, you get the full path. If you have still further doubts, email me at anilms@justsystem.co.jp
ListBox1.Items.Add(FileLis
If you add the directory property, you get the full path. If you have still further doubts, email me at anilms@justsystem.co.jp
Ps : I missed out a '\'.
ListBox1.Items.Add(FileLis tBox1.Dire ctory+'\'+ FileListBo x1.Items[i ])
ListBox1.Items.Add(FileLis
ASKER
anilms...
Did you get my e-mail from earlier today? Your suggestion is not quite right. It puts two '\' wheever you select files from a root directory like C:\. How to solve this?
Regards,
Shawn Halfpenny
drumme59@sprint.ca
Did you get my e-mail from earlier today? Your suggestion is not quite right. It puts two '\' wheever you select files from a root directory like C:\. How to solve this?
Regards,
Shawn Halfpenny
drumme59@sprint.ca
There is a way out. Just check what is the last character in FileListBox.Directory. If it is not a '\', then add it.
if FileListBox1.Directory[len gth(FileLi stBox1.Dir ectory)]<> '\' then
FileListBox1.Directory := FileListBox1.Directory+'\' ;
if FileListBox1.Directory[len
FileListBox1.Directory := FileListBox1.Directory+'\'
ASKER
Thanks for leaving me the joy of getting it to work with a file list... I couldn't. The only problem is I'm having trouble using the 'FileName' property to add the fully qualified filename to my listbox. Here's what I've got:
if Button = mbRight then
begin
if FileListBox1.SelCount > 1 then
for i:=0 to FileListBox1.Items.Count-1
if FileListBox1.Selected[i] then
ListBox1.Items.Add(FileLis
end;
..This doesn't work. It doesn't like the 'FileName' after 'items[i]'. I NEED to have the fully qualified filename and pathname in the ListBox, so it would appear I need to use the 'FileName' property in some way....but how??
Thanks,
Shawn Halfpenny