By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,989 Members | 1,457 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,989 IT Pros & Developers. It's quick & easy.

need a good idea :)

P: n/a
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
Share this Question
Share on Google+
10 Replies


P: n/a
"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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
"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

P: n/a


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

P: n/a

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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.