473,320 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

need a good idea :)

Hi all,

i need some help here plz :)
i'm building a small application that will dispaly a list of folders
in a listbox, but i only want to display the folder name rather than
the whole path, so i take the substring from the whole path and add it
to the listbox.
the problem is, later, when the user selects to do anything with this
file, i want to get the whole path back(mandatory), but now i only
have the the name and not the path.

the dummy solution i do, is to get the index of the selected index and
then get the path from teh path list at that index, but i don't like
such a solution, i think its not professional nor efficient.

so any ideas??

i'm using VS2003, c# to build a desktop application
thanks for time and help

Jan 30 '07 #1
10 1465
"xxxx" <xx******@gmail.comwrote in message
news:11**********************@a75g2000cwd.googlegr oups.com...
so any ideas??
Use the filespec as the Value property of the ListItem and use the filename
as the Text property of the ListItem.
Jan 30 '07 #2
Could you not populate the Tag Property and read it from there?



"xxxx" <xx******@gmail.comwrote in message
news:11**********************@a75g2000cwd.googlegr oups.com...
Hi all,

i need some help here plz :)
i'm building a small application that will dispaly a list of folders
in a listbox, but i only want to display the folder name rather than
the whole path, so i take the substring from the whole path and add it
to the listbox.
the problem is, later, when the user selects to do anything with this
file, i want to get the whole path back(mandatory), but now i only
have the the name and not the path.

the dummy solution i do, is to get the index of the selected index and
then get the path from teh path list at that index, but i don't like
such a solution, i think its not professional nor efficient.

so any ideas??

i'm using VS2003, c# to build a desktop application
thanks for time and help

Jan 30 '07 #3
i tried using the listitem, but it was not defined.
i guess its applicable for asp.net applications only, i'm trying to
build a desktop application.

On Jan 30, 1:29 pm, "Mark Rae" <m...@markNOSPAMrae.comwrote:
"xxxx" <xxxxl...@gmail.comwrote in messagenews:11**********************@a75g2000cwd.g ooglegroups.com...
so any ideas??Use the filespec as the Value property of the ListItem and use the filename
as the Text property of the ListItem.
Jan 30 '07 #4
as long as i know, this Tag property is related to the listbox itself,
not to an item in the list, am i wrong??
On Jan 30, 1:28 pm, "iKiLL" <i...@NotMyEmail.comwrote:
Could you not populate the Tag Property and read it from there?

"xxxx" <xxxxl...@gmail.comwrote in messagenews:11**********************@a75g2000cwd.g ooglegroups.com...
Hi all,
i need some help here plz :)
i'm building a small application that will dispaly a list of folders
in a listbox, but i only want to display the folder name rather than
the whole path, so i take the substring from the whole path and add it
to the listbox.
the problem is, later, when the user selects to do anything with this
file, i want to get the whole path back(mandatory), but now i only
have the the name and not the path.
the dummy solution i do, is to get the index of the selected index and
then get the path from teh path list at that index, but i don't like
such a solution, i think its not professional nor efficient.
so any ideas??
i'm using VS2003, c# to build a desktop application
thanks for time and help- Hide quoted text -- Show quoted text -
Jan 30 '07 #5
In addition to the other comments, you probably want to take a look at
Path.GetFileName instead of all that substring "stuff":

http://msdn2.microsoft.com/en-us/lib...tfilename.aspx

Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"xxxx" wrote:
Hi all,

i need some help here plz :)
i'm building a small application that will dispaly a list of folders
in a listbox, but i only want to display the folder name rather than
the whole path, so i take the substring from the whole path and add it
to the listbox.
the problem is, later, when the user selects to do anything with this
file, i want to get the whole path back(mandatory), but now i only
have the the name and not the path.

the dummy solution i do, is to get the index of the selected index and
then get the path from teh path list at that index, but i don't like
such a solution, i think its not professional nor efficient.

so any ideas??

i'm using VS2003, c# to build a desktop application
thanks for time and help

Jan 30 '07 #6
"xxxx" <xx******@gmail.comwrote in message
news:11*********************@s48g2000cws.googlegro ups.com...
>i tried using the listitem, but it was not defined.
i guess its applicable for asp.net applications only, i'm trying to
build a desktop application.
You can use the ListItem object from the System.Web.UI.WebControls namespace
in a dektop application - it's just another part of the Framework. I do this
all the time...

MyListItem = new System.Web.UI.WebControls.ListItem();

etc.
Jan 30 '07 #7


On 30 Jan., 12:20, "xxxx" <xxxxl...@gmail.comwrote:
Hi all,

i need some help here plz :)
i'm building a small application that will dispaly a list of folders
in a listbox, but i only want to display the folder name rather than
the whole path, so i take the substring from the whole path and add it
to the listbox.
the problem is, later, when the user selects to do anything with this
file, i want to get the whole path back(mandatory), but now i only
have the the name and not the path.

the dummy solution i do, is to get the index of the selected index and
then get the path from teh path list at that index, but i don't like
such a solution, i think its not professional nor efficient.

so any ideas??

i'm using VS2003, c# to build a desktop application

thanks for time and help
The Tag property is on all controls. It is not used by the framework,
it is meant to be used for user data. So when you populate your
ListView, you may do it like this:
ListViewItem lvi = new ListViewItem();
lvi.Text = Path.GetFileName(fullPath);
lvi.Tag = fullPath;
listView1.Items.Add(lvi);

-but it is good style to create a small class for your purpose similar
to this:
private class FolderListViewTag {
public string Path;

public override string ToString() {
return Path.GetFileName(Path);
}
}
-and then put instances of this one into the Tag property. Then,
later, when you find out you need more data, or you need to alter the
string representation of each ListViewItem or you need to make it
configurable, or whatever, then it will require a minimal change.

Good luck :o)

Jan 30 '07 #8

thanks for the great help,

but when i try out this piece of code, i don't get my string in the
listbox, instead i get something like ListViewItem:{Webapplication1}
instead of WebApplication1 :(

On Jan 30, 3:53 pm, "mookid" <mookid8...@gmail.comwrote:
On 30 Jan., 12:20, "xxxx" <xxxxl...@gmail.comwrote:


Hi all,
i need some help here plz :)
i'm building a small application that will dispaly a list of folders
in a listbox, but i only want to display the folder name rather than
the whole path, so i take the substring from the whole path and add it
to the listbox.
the problem is, later, when the user selects to do anything with this
file, i want to get the whole path back(mandatory), but now i only
have the the name and not the path.
the dummy solution i do, is to get the index of the selected index and
then get the path from teh path list at that index, but i don't like
such a solution, i think its not professional nor efficient.
so any ideas??
i'm using VS2003, c# to build a desktop application
thanks for time and helpThe Tag property is on all controls. It is not used by the framework,
it is meant to be used for user data. So when you populate your
ListView, you may do it like this:
ListViewItem lvi = new ListViewItem();
lvi.Text = Path.GetFileName(fullPath);
lvi.Tag = fullPath;
listView1.Items.Add(lvi);

-but it is good style to create a small class for your purpose similar
to this:
private class FolderListViewTag {
public string Path;

public override string ToString() {
return Path.GetFileName(Path);
}}-and then put instances of this one into the Tag property. Then,
later, when you find out you need more data, or you need to alter the
string representation of each ListViewItem or you need to make it
configurable, or whatever, then it will require a minimal change.

Good luck :o)- Hide quoted text -- Show quoted text -
Jan 30 '07 #9
So, if it's a ListViewItem, that's a class. You can cast it to type
ListViewItem and get the value from it's properties.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"xxxx" wrote:
>
thanks for the great help,

but when i try out this piece of code, i don't get my string in the
listbox, instead i get something like ListViewItem:{Webapplication1}
instead of WebApplication1 :(

On Jan 30, 3:53 pm, "mookid" <mookid8...@gmail.comwrote:
On 30 Jan., 12:20, "xxxx" <xxxxl...@gmail.comwrote:


Hi all,
i need some help here plz :)
i'm building a small application that will dispaly a list of folders
in a listbox, but i only want to display the folder name rather than
the whole path, so i take the substring from the whole path and add it
to the listbox.
the problem is, later, when the user selects to do anything with this
file, i want to get the whole path back(mandatory), but now i only
have the the name and not the path.
the dummy solution i do, is to get the index of the selected index and
then get the path from teh path list at that index, but i don't like
such a solution, i think its not professional nor efficient.
so any ideas??
i'm using VS2003, c# to build a desktop application
thanks for time and helpThe Tag property is on all controls. It is not used by the framework,
it is meant to be used for user data. So when you populate your
ListView, you may do it like this:
ListViewItem lvi = new ListViewItem();
lvi.Text = Path.GetFileName(fullPath);
lvi.Tag = fullPath;
listView1.Items.Add(lvi);

-but it is good style to create a small class for your purpose similar
to this:
private class FolderListViewTag {
public string Path;

public override string ToString() {
return Path.GetFileName(Path);
}}-and then put instances of this one into the Tag property. Then,
later, when you find out you need more data, or you need to alter the
string representation of each ListViewItem or you need to make it
configurable, or whatever, then it will require a minimal change.

Good luck :o)- Hide quoted text -- Show quoted text -

Jan 30 '07 #10
In windows forms you can put any object into a list box, with the
result of ToString() displayed as the list box text.

So create a wrapper class for your file name, holding both the full
path and the file name:
public class Wrapper
{
private string _path;
private string _fileName;

public Wrapper(string path)
{
_path = path;
_fileName = System.IO.Path.GetFileName(_path);
}

public string Path
{
get
{
return _path;
}
}

public override string ToString()
{
return _fileName;
}
}

Then add objects of this type to the listbox:
myListBox.Items.Add(new Wrapper(@"C:\path\to\file"));

Then you the selected item will be of your type, e.g.
Wrapper selected = myListBox.SelectedItem as Wrapper;
if(selected != null)
{
MessageBox.Show(selected.Path + " was selected");
}

hth
Terry

On Jan 30, 11:20 am, "xxxx" <xxxxl...@gmail.comwrote:
Hi all,

i need some help here plz :)
i'm building a small application that will dispaly a list of folders
in a listbox, but i only want to display the folder name rather than
the whole path, so i take the substring from the whole path and add it
to the listbox.
the problem is, later, when the user selects to do anything with this
file, i want to get the whole path back(mandatory), but now i only
have the the name and not the path.

the dummy solution i do, is to get the index of the selected index and
then get the path from teh path list at that index, but i don't like
such a solution, i think its not professional nor efficient.

so any ideas??

i'm using VS2003, c# to build a desktop application

thanks for time and help
Jan 30 '07 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: mr.iali | last post by:
Hi Everyone I would like to get into software developent using a programming language like c++, java or pl/sql for oracle. I have no idea where to start from. Which language is there more...
4
by: nsr93 | last post by:
I am not sure if this was the proper group to post this, but here is my question: I am a Java consultant. I have new client I am working for to make a web based application similar to an...
6
by: Martijn van Oosterhout | last post by:
I've had some fun in the past where I've had to grant a lot of tables and other similar system commands. Unfortunatly, you can't use queries to fill in fields for you. Anyway, I've implemented a...
19
by: James Fortune | last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't understand why people who know how to write code to completely replace a front end do not write something that will automate...
48
by: Chad Z. Hower aka Kudzu | last post by:
A few of you may recognize me from the recent posts I have made about Indy <http://www.indyproject.org/indy.html> Those of you coming to .net from the Delphi world know truly how unique and...
15
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to...
4
by: robinsand | last post by:
My apologies to those of you who are more advanced Visual C++ .NET programmers, but I am working on a project for an MBA course that is condensed into an eight-week schedule, and I need help...
46
by: Bruce W. Darby | last post by:
This will be my very first VB.Net application and it's pretty simple. But I've got a snag in my syntax somewhere. Was hoping that someone could point me in the right direction. The history: My...
20
by: mike | last post by:
I help manage a large web site, one that has over 600 html pages... It's a reference site for ham radio folks and as an example, one page indexes over 1.8 gb of on-line PDF documents. The site...
7
by: elgiei | last post by:
Good morning at all, i have to implement a server,that every n-seconds (eg. 10sec) sends to other clients,which files and directory has been deleted or modified. i build a n-tree, for each...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.