Solved

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

Posted on 2003-10-25
2
170 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
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
When I am typing into a TEdit last word repeats 7 147
creating threads in delphi 1 135
Performance of SQL statement 37 127
Base1 Encode/Decode 3 82
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
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…

832 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