• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 374
  • Last Modified:

ListView/Imageview

I am trying to make an app that will display small "thumbnail" images for same size bitmaps in a common directory.  I am trying to use a listview and an imagelist to accomplish this with little success.  One problem is I can't get it to display all the images and when I do try to do it manually, it will diplay the filename for each file, but the bitmap it displays for every file is the first one I click on.  If I close the app and restart it, the first image I click on is the correct one, but all subsequent files display the bitmap image of the first one I clicked on.  Does anyone have any suggestions or sample code I could look at?  I would really appreciate it.
Jason
0
jason03
Asked:
jason03
  • 3
1 Solution
 
cjm30305Commented:
I am posting 3 times.  Once to explain it, then I am going to post the form file, then the unit.  make sure you double click the selected directory twice to make sure it loads the files in the list box.  This is very crude, but does function properly.

Hope this helps.

Cheers.
0
 
cjm30305Commented:
object Form1: TForm1
  Left = 387
  Top = 227
  Width = 653
  Height = 371
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Image1: TImage
    Left = 280
    Top = 216
    Width = 105
    Height = 105
  end
  object ListView1: TListView
    Left = 216
    Top = 48
    Width = 250
    Height = 150
    Columns = <>
    TabOrder = 0
    ViewStyle = vsList
    OnClick = ListView1Click
  end
  object DirectoryListBox1: TDirectoryListBox
    Left = 8
    Top = 48
    Width = 201
    Height = 153
    ItemHeight = 16
    TabOrder = 1
    OnDblClick = DirectoryListBox1DblClick
  end
  object DriveComboBox1: TDriveComboBox
    Left = 8
    Top = 208
    Width = 201
    Height = 19
    TabOrder = 2
    OnChange = DriveComboBox1Change
  end
  object FileListBox1: TFileListBox
    Left = 472
    Top = 48
    Width = 97
    Height = 17
    ItemHeight = 13
    Mask = '*.bmp'
    TabOrder = 3
    Visible = False
  end
end
0
 
cjm30305Commented:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, FileCtrl, ComCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    ListView1: TListView;
    DirectoryListBox1: TDirectoryListBox;
    DriveComboBox1: TDriveComboBox;
    FileListBox1: TFileListBox;
    Image1: TImage;
    procedure DriveComboBox1Change(Sender: TObject);
    procedure DirectoryListBox1DblClick(Sender: TObject);
    procedure ListView1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.DriveComboBox1Change(Sender: TObject);
begin
  DirectoryListBox1.Drive := DriveComboBox1.Drive;
end;

procedure TForm1.DirectoryListBox1DblClick(Sender: TObject);
var
 i: Integer;
begin
  ListView1.Items.Clear;
 
  FileListBox1.Directory := DirectoryListBox1.Directory;

  for i := 0 to FileListBox1.Items.Count - 1 do
   begin
    ListView1.Items.Add.Caption := FileListBox1.Items.Strings[i];
   end;
end;

procedure TForm1.ListView1Click(Sender: TObject);
var
 Dir: string;
 Filename: string;
begin
  Dir := DirectoryListBox1.Directory;
  Filename := ListView1.Selected.Caption;
  Filename := Dir + '\' + Filename;

  Image1.Picture.LoadFromFile(Filename);
end;

end.
0
 
CleanupPingCommented:
jason03:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
kacorretiredCommented:
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 for this question:
       to accept cjm30305's answer
Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

kacor
EE Cleanup Volunteer
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now