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] > 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