Groups | Blog | Home
all groups > dotnet framework > january 2007 >

dotnet framework : need a good idea :)


xxxx
1/30/2007 3:20:36 AM
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 NO[at]SPAM gmx.net
1/30/2007 4:29:54 AM
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:

[quoted text, click to view]
Kevin Spencer
1/30/2007 7:42:41 AM
Put the full path into the Tag property of the ListItem.

--
HTH,

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

The shortest distance between 2 points is a curve.

[quoted text, click to view]

Alvin Bruney [MVP]
1/30/2007 6:03:47 PM
Did I not see this message in C# newsgroups with a bunch of replies? Why
post here again?

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


[quoted text, click to view]

Massimo
1/30/2007 7:01:25 PM
"xxxx" <xxxxlike@gmail.com> ha scritto nel messaggio
news:1170156036.839382.220790@q2g2000cwa.googlegroups.com...

[quoted text, click to view]

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
AddThis Social Bookmark Button