Board index » delphi » TCheckBox and FileList

TCheckBox and FileList

All,

  What is an easy way to populate the Items list of a TCheckBox component
by somehow obtaining a list of files from a certain directory?

  Example:

   Want all the files in c:\windows to show up in a check box list so the
user can check/uncheck certain files.

Thanks,

Zack

 

Re:TCheckBox and FileList


example with TCheckList

procedure TForm1.Button1Click(Sender: TObject);
var
  f : TSearchRec;
begin
  if findfirst('c:\windows\*.*',faAnyFile,f) = 0 then begin
    repeat
      checkList.Items.Add(f.Name);
    until FindNext(f) <> 0;
    FindClose(f);
  end;
end;

The code would populate, in the same way, a listbox or combobox control,
but you are in deeper water if you want a combobox with checkboxes as
this control doesnt exist in standard delphi.

Kind Regards
Claire, c...@HallworthHome.demon.co.uk

Re:TCheckBox and FileList


Ehh.... don't really wanna make you look silly, but what Items property in a
TCheckBox ?

You might have a certain Checkboxlist component where I assume the Items is
a TStrings or TStringlist where you can do

Items.Assign(MyStringlist);

after you filled MyStringList with the files offcourse which you can
retreive with FindFirst/FindNext which are documented somewhere

Roel

Quote
Zachary Burns <zbu...@katzmidas.com> wrote:
> All,
>   What is an easy way to populate the Items list of a TCheckBox component
> by somehow obtaining a list of files from a certain directory?
>   Example:
>    Want all the files in c:\windows to show up in a check box list so the
> user can check/uncheck certain files.
> Thanks,
> Zack

Re:TCheckBox and FileList


Quote
Zachary Burns wrote:

> All,

>   What is an easy way to populate the Items list of a TCheckBox component
> by somehow obtaining a list of files from a certain directory?

>   Example:

>    Want all the files in c:\windows to show up in a check box list so the
> user can check/uncheck certain files.

> Thanks,

> Zack

This works for me.  It loads all the values from a TreeView into a
scrollable CheckListBox.

procedure TForm_PersonalAssignments.FormActivate(Sender: TObject);
var
  I:                         Integer;

begin
  Screen.Cursor:=crHourGlass;
  With Form_AIA_Main.TreeView1 do begin
    For I:=0 to Items.Count-1 do
      CheckListBox1.Items.Add(Items[I].Text);
  end;
  Screen.Cursor:=crDefault;
end;

Re:TCheckBox and FileList


In article <01bde18d$bd1bdc80$1d190dd0@rd>, "Zachary Burns"

Quote
<zbu...@katzmidas.com> writes:
> What is an easy way to populate the Items list of a TCheckBox component
>by somehow obtaining a list of files from a certain directory?

I assume you mean a CheckListBox? Is:

procedure TForm1.FillCheckListBox(L: TCheckListBox; Path: string);
begin
  if SendMessage(L.Handle,LB_DIR,DDL_DIRECTORY,LPARAM(PChar(Path))) =
  LB_ERR then raise Exception.Create('Error listing files');
end;

easy enough?

Charles Johnson

Other Threads