Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / January 2007

Tip: Looking for answers? Try searching our database.

need a good idea :)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
xxxx - 30 Jan 2007 11:20 GMT
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
kies98@gmx.net - 30 Jan 2007 12:29 GMT
Hi,

you could create a DataTable with two columns. One contains the whole
path and one only the part that should get displayed. Bind that
Datatable to your ListBox as a Datasource and set the listbox's
DisplayMember and ValueMember properties to the name of your first and
second column respectively. To get the value you simply query the
Listbox1.SelectedValue property and you are done...

Add a listbox to your Form to get this code running.

           DataTable myDataTable = new DataTable();
           myDataTable.Columns.Add("Value");
           myDataTable.Columns.Add("Text");
           myDataTable.Rows.Add(new object[] { @"C:\Windows",
"Windows" });
           listBox1.DataSource = myDataTable;
           listBox1.DisplayMember =
myDataTable.Columns[1].ColumnName;
           listBox1.ValueMember = myDataTable.Columns[0].ColumnName;

           listBox1.SelectedIndex = 0;
           MessageBox.Show( listBox1.SelectedValue.ToString() );

Another Tip: Try to use the class System.IO.Path - It can save you a
lot of work and you don't need to substring the paths...

Hope that was of any help - regards

xxxx schrieb:

> Hi all,
>
[quoted text clipped - 16 lines]
>
> thanks for time and help
Kevin Spencer - 30 Jan 2007 12:42 GMT
Put the full path into the Tag property of the ListItem.

Signature

HTH,

Kevin Spencer
Microsoft MVP
Software Composer
http://unclechutney.blogspot.com

The shortest distance between 2 points is a curve.

> Hi all,
>
[quoted text clipped - 16 lines]
>
> thanks for time and help
Massimo - 30 Jan 2007 18:01 GMT
> so any ideas??
>
> i'm using VS2003, c# to build a desktop application

Create an array of strings and store the paths in it, then use the selected
index to lookup the full path string in the array.

Massimo
Alvin Bruney [MVP] - 30 Jan 2007 23:03 GMT
Did I not see this message in C# newsgroups with a bunch of replies? Why
post here again?

Signature

Regards,
Alvin Bruney
------------------------------------------------------
Shameless author plug
Excel Services for .NET is coming...
OWC Black book on Amazon and
www.lulu.com/owc

> Hi all,
>
[quoted text clipped - 16 lines]
>
> thanks for time and help

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.