Solved

incorporating the path of the file that will be displayed in the listbox

Posted on 2003-10-25
2
167 Views
Last Modified: 2011-09-20
Hi, how can we incorporate the path of a file that will be added to the listbox
without having it to be displayed in the listbox.. example>
what i want is that in the list box it will display

z21001.zip but it carries the path of this file silently..

and not this one

c:\progra~1\z21001.zip


in the list its just z21001.zip.. hope you understand.. thanks





0
Comment
Question by:orafans
2 Comments
 
LVL 8

Expert Comment

by:gmayo
Comment Utility
Either:
1. Have a seperate string list which stores the full path
2. Use OwnerDraw so that you draw the item yourself - internally it would be stored with the path but when you display it, just draw ExtractFileName(path).

Example for 2:
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer; Rect:TRect;State: TOwnerDrawState);
begin
      with (Control as TListBox).Canvas do  { draw on control canvas, not on the form }
      begin
            FillRect(Rect);       { clear the rectangle }
            TextOut(Rect.Left, Rect.Top, ExtractFileName((Control as TListBox).Items[Index]))
      end;
end;

Geoff M.
0
 
LVL 4

Accepted Solution

by:
nestorua earned 125 total points
Comment Utility
HI,
You can do it the following way (very useful indeed):

TYPE
 TPathStr=class
   FullPath: string;
    constructor Create(AFullPath: string);
  end;

{ TMyStr }
constructor TPathStr.Create(AFullPath: string);
begin
 Inherited Create;
 FullPath:=AFullPath;
end;

procedure TForm1.AddItemToListBox(FileName: string);
begin
 with ListBox1.Items do
    AddObject(ExtractFileName(FileName), TPathStr.Create(FileName));
end;
Sincerely,
Nestorua.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now