Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to populate a combox? 1

Status
Not open for further replies.

pierrotsc

Programmer
Nov 25, 2007
358
0
0
US
I have a directory with a lot of files. I would like to populate my combobox with their names.How do i do that?
Thanks.
 
Loading a comboBox with the file names is not all that difficult, what you're going to want to look at is how to keep it in synch with file names that may be deleted or added after it is initially populated...

To simply populate (with only file names, not directories)
Code:
procedure TForm1.LoadCombBox;
var
   S2: TSearchRec;
   Path, Filter: String;
begin
   Path := 'C:\myPath\';
   Filter := '*.*';
   ComboBox1.Clear;
   if FindFirst(Path+Filter, faAnyfile-faDirectory, S2) = 0 then
   try
      repeat
         combobox1.Items.Add(S2.Name);
      until FindNext(S2) <> 0;
   finally
      FindClose(S2);
   end;
   ComboBox1.ItemIndex := 0;
end;

You can call this method in the formCreate method.

To keep the files in synch, you may want to look at this component.


Set up a watch on the same directory, and makes the changes to your combobox as it notifies of any changes.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top