Solved

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

Posted on 2003-10-25
2
172 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 8

Expert Comment

by:gmayo
ID: 9619219
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
ID: 9619571
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

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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

734 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