473,503 Members | 1,858 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ListBox issue

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
12 1855
* "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
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
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
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
* "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
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
* "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
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
* "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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3602
by: JoeHenrich | last post by:
I am using VS.NET 2003 and am having an interesting issue with a Listbox control. Essentially, I have a form with a listbox on it. In the listbox doubleclick event I would like to do some...
8
2865
by: Oddball | last post by:
Ok - I have a ListBox control and I'm ready to write my own DrawItem event handler. What I want to draw as the item is another control. I have created a user control that I would like to list in...
10
2223
by: yop | last post by:
All When I try to get the text from my listbox I am get an error which is listed below. Any ideas? Thanks Object reference not set to an instance of an object.
3
2890
by: Dean Slindee | last post by:
In a checked listbox, I am allowing drag/drop of the items within (resequencing). Problem is, when dropping a checked item, the checked state always reverts to unchecked (unwanted). Anyone know...
2
1420
by: Rlrcstr | last post by:
I'm rolling my own with a listbox. The items in the list box are of varying sizes and I'm hit checking when the litbox is checked to see what portion of an item the user has clicked on. Mostly...
6
9910
by: Mark | last post by:
Hello. I have a listbox whose rowsource is set to a saved query (call it "qry_customer_list.") When I add customers to my database, I call the listbox Requery method so that the listbox will...
2
2073
by: Steve Potter | last post by:
I am trying to find some method of attaching a Listbox object to a list object so as the contents of the list are changed the contents of the Listbox will be updated to match. I have found a few...
18
4582
by: Zytan | last post by:
I want the same function to be run whether you press Enter or double click the listbox. It seems really verbose to write both handlers to both events everytime, even if they both call the same...
15
2339
by: Doogie | last post by:
I have a .net app that a user currently enters a number in a text box, hits a button and a data call is executed. She wants the ability to enter in multiple numbers (up to 100). So to make...
5
2657
by: MelindaM | last post by:
Hi guys, I created a form for searching through a parts library that I have stored in a MySQL database. I'm not new to web programming but this is my first time using PHP and Ajax. I have four...
0
7086
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7280
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6991
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7460
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3167
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1512
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.