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

ListBox issue

P: n/a
I know that I can use DisplayMember and ValueMember when using a DataSource
on the ListBox, but is it possible to use the same technique when using
ListBox.Items.Add method? In my application I use a OpenFileDialog to let
the user select filenames into the ListBox. The problem is that I don't
wish to show the path + filename in the ListBox, only the filename. But I
need the full path to know where the file is so I can't just chop it off. I
could use DataSource with DisplayMember and ValueMember, but then I won't be
able to remove any of the items in the ListBox, and I have to be able to do
that...

Any help is greatly appreciated.
Shawn
Nov 20 '05 #1
Share this Question
Share on Google+
12 Replies


P: n/a
* "Shawn" <bo********@hotmail.com> scripsit:
I know that I can use DisplayMember and ValueMember when using a DataSource
on the ListBox, but is it possible to use the same technique when using
ListBox.Items.Add method? In my application I use a OpenFileDialog to let
the user select filenames into the ListBox. The problem is that I don't
wish to show the path + filename in the ListBox, only the filename. But I
need the full path to know where the file is so I can't just chop it off. I
could use DataSource with DisplayMember and ValueMember, but then I won't be
able to remove any of the items in the ListBox, and I have to be able to do
that...


Have a look at the code, ignore the text:

<http://www.mvps.org/dotnet/dotnet/code/controls/index.html#bkm10>

--
Herfried K. Wagner
MVP VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #2

P: n/a
Cor
Herfried,
I have ignored the text, but the question was how without a dataset and the
anwer is with a dataset, that you can find normal on MSDN.
What is the question, and I am intrested too.

Just something in pseudocode
\\\
Dim alistbox as new listbox
dim alistitem as new listitem
listitem.add("Herfried","Austria")
alistbox.items.add(listitem)
///

As far as I know this is easy on a webform, but I could not find any
documentation on a window form for that.

Do you know where to can find it, or was it on that page and could I not
understand that language (not true).
:-)
Cor
Nov 20 '05 #3

P: n/a
Hi Shawn,

What Herfried's example is showing is that you can stick any object into
the ListBox. The ListBox will use the ToString method for display purposes,
but when you access the list in your code, you get the whole object.

You could have a class or structure which holds the full filepath and has
a ToString method returning just the tail end.

Regards,
Fergus
Nov 20 '05 #4

P: n/a
Thanks a lot!

Shawn

"Fergus Cooney" <fi******@tesco.net> wrote in message
news:ej**************@tk2msftngp13.phx.gbl...
Hi Shawn,

What Herfried's example is showing is that you can stick any object into
the ListBox. The ListBox will use the ToString method for display purposes,
but when you access the list in your code, you get the whole object.

You could have a class or structure which holds the full filepath and
has
a ToString method returning just the tail end.

Regards,
Fergus

Nov 20 '05 #5

P: n/a
* "Fergus Cooney" <fi******@tesco.net> scripsit:
What Herfried's example is showing is that you can stick any object into
the ListBox. The ListBox will use the ToString method for display purposes,
but when you access the list in your code, you get the whole object.


My sample shows how to do that with a combobox, but it works similar
with a listbox. The code is self-explaining.

--
Herfried K. Wagner
MVP VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #6

P: n/a
Hi Shawn,

I'm very curious and I'd love the answers to these questions. You <cannot>
answer them wrongly (for this is not about you personally).

1 Did you follow Herfried's link?
2 What where your reactions when you got there?
3 What effect did seeing a load of German text have?
4 Did you examine the code?
5 Did you realise that there were two bits of code to examine?
6 Did it give a hint, make complete sense, or what?

Please answer these - we're talking valuable feedback here. ;-))

Regards,
Fergus
Nov 20 '05 #7

P: n/a
* "Fergus Cooney" <fi******@tesco.net> scripsit:
I'm very curious and I'd love the answers to these questions. You <cannot>
answer them wrongly (for this is not about you personally).

1 Did you follow Herfried's link?
2 What where your reactions when you got there?
3 What effect did seeing a load of German text have?
4 Did you examine the code?
5 Did you realise that there were two bits of code to examine?
6 Did it give a hint, make complete sense, or what?

Please answer these - we're talking valuable feedback here. ;-))


ROFLM*O

--
Herfried K. Wagner
MVP VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #8

P: n/a
Cor
Hi Herfried,
I see everybody gets an answer yes,
:-((
My question was what was as well in the question, can you do it without a
datasource in a windowsform?.

Cor
Nov 20 '05 #9

P: n/a
* "Cor" <no*@non.com> scripsit:
My question was what was as well in the question, can you do it without a
datasource in a windowsform?.


What exactly do you want to do?

--
Herfried K. Wagner
MVP VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #10

P: n/a
Cor
Hi Herfried,
This was the origonal question.
I know that I can use DisplayMember and ValueMember when using a DataSourceon the ListBox, but is it possible to use the same technique when using
ListBox.Items.Add method


And I am curious about it because I did search a long time.

It would be easy if the add was overloaded, but it seems to me not, or that
there was a possibility as on the listbox from the webform (adding
listitems).

Cor
Nov 20 '05 #11

P: n/a
Hi Cor.
What I learned was that I could put almost anything into a ListBox, you can
even add a System.Web.UI.WebControls.ListItem. Like this:
myListItem.Items.Add(New
system.Web.UI.WebControls.ListItem("test.txt","C:\ temp\test.txt")) The
first parameter will be the equivalent of DisplayMember and the second will
be the equivalent of ValueMember.

Was this what you were looking for?
Shawn

"Cor" <no*@non.com> wrote in message
news:3f***********************@reader20.wxs.nl...
Hi Herfried,
This was the origonal question.
I know that I can use DisplayMember and ValueMember when using a DataSourceon the ListBox, but is it possible to use the same technique when using
ListBox.Items.Add method


And I am curious about it because I did search a long time.

It would be easy if the add was overloaded, but it seems to me not, or that
there was a possibility as on the listbox from the webform (adding
listitems).

Cor

Nov 20 '05 #12

P: n/a
Cor
Shawn,
This is about a "winform" listbox. I get the idea it is totaly different
from a "webform", while most controls with the same name are something the
same (absolute not totaly).

So I am curious if that with the listbox is true.

That behaviour with a listbox on a webcontrol, do I find very nice,
therefore I don't totaly not understand why that "easy" way is not on a
window form

Cor
Nov 20 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.