我想在combobox的下拉框中有计算机的所有硬盘分区,并且当我选择分区时,在listbox中显示该分区中的目录,如何实现呀?如果能给出源代码,不胜感激

解决方案 »

  1.   

    这位朋友,你好,按照你所说,你可以用Delphi现成的控件TShellComboBox来实现你所说的功能,根本不用写代码,再组合TShellTreeView和TShellListView,相信你会很好地解决好你的这个问题,以上三个控件在Delphi6及以上版本都有,你可以试一下。
      

  2.   

    Delphi有现成控件,在Win31标签页
      

  3.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
    x:integer;
    drive:char;
    y:integer;
    begin
    x:=0;
    y:=0;
    x:=GetLogicalDrives();
    repeat
    x:=  x div 2 ;
    Y:=Y+1;
    until x=1;
    x:=0;
        for drive:='a' to 'z' do
        begin
          Case GetDriveType(pchar(Drive+':\')) of
            2: Label1.Caption :='软盘驱动器';
            3: Label1.Caption := '硬盘驱动器';
            4: Label1.Caption := '网络驱动器';
            5: Label1.Caption := 'CD-ROM驱动器';
            6: Label1.Caption := '虚拟驱动器';
          Else Label1.Caption := '驱动器无效';
          end;
        if GetDriveType(pchar(Drive+':\'))in[2,3,4,5,6] then
        ComboBox1.Items.Add(pchar(drive+':\    ')+label1.Caption);
        x:=x+1;
        if x>y then begin
          showmessage('Done !');
          exit;
          end;
        end;
    end;procedure TForm1.ComboBox1Change(Sender: TObject);var
       SearchRec:TSearchRec;
       ext,AppPath:string;
    begin
        listbox1.Items.Clear;
         AppPath:=copy(combobox1.Items.Strings[combobox1.itemindex],1,3);
         ext:='*.*';
         FindFirst(AppPath+ext,faDirectory,SearchRec);
         listbox1.Items.Add(SearchRec.Name);
         while FindNext(SearchRec)=0 do
           listbox1.Items.Add(SearchRec.Name);
    end;
      

  4.   

    先按button1,然后就可以实现你要的功能,如果有问题给我发信息
      

  5.   

    TShellComboBox
    TShellTreeView
    TShellListView
      

  6.   

    delphi自带的控件就可以完成了啊。
      

  7.   

    同志们说的有道理,你可以不用combobox,换个控件不用加几句码的。