473,386 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Referencing Objects in a listbox

This is sort of a newbie question, but it's making me crazy.

I have a project (VB.Net) in which data is read from a source file.
That data is used to create instances of the class "OrderItem" and a
list box (Supplies) is populated with those items. This part works.

If the user double-clicks an item on the list box, it checks to see if
that item appears on another list box (On Order) to see if it has
already been ordered.

Normally, I just cast the item on the list as a string
(CStr(lstSupplies.Items(lstSupplies.SelectedIndex) ) and search the
other list box for it, but this time I can't seem to cast an
"OrderItem" as a "String". I'm assuming it's because my collection is
objects and not just text strings, but I can't seem to come up with a
workaround. BTW, items are listed (sorted) by their description via a
ToString function within the class.

Any and all help is appreciated.
Nov 20 '05 #1
2 1094
Larry,

don't cast them, call their ToString-Method to get the string with which you
are searching the second list (Actually, you already kind of wrote that
yourself in the last paragraph ;-)

Klaus

"LarryMac" <la********@msn.com> schrieb im Newsbeitrag
news:dd*************************@posting.google.co m...
This is sort of a newbie question, but it's making me crazy.

I have a project (VB.Net) in which data is read from a source file.
That data is used to create instances of the class "OrderItem" and a
list box (Supplies) is populated with those items. This part works.

If the user double-clicks an item on the list box, it checks to see if
that item appears on another list box (On Order) to see if it has
already been ordered.

Normally, I just cast the item on the list as a string
(CStr(lstSupplies.Items(lstSupplies.SelectedIndex) ) and search the
other list box for it, but this time I can't seem to cast an
"OrderItem" as a "String". I'm assuming it's because my collection is
objects and not just text strings, but I can't seem to come up with a
workaround. BTW, items are listed (sorted) by their description via a
ToString function within the class.

Any and all help is appreciated.

Nov 20 '05 #2
Thanks, I sorta knew what I was doing wrong, and almost knew what I
had to do...I just couldn't seem to make that final leap.

"Klaus Löffelmann" <fo***********@loeffelmann.de> wrote in message news:<eT**************@TK2MSFTNGP09.phx.gbl>...
Larry,

don't cast them, call their ToString-Method to get the string with which you
are searching the second list (Actually, you already kind of wrote that
yourself in the last paragraph ;-)

Klaus

"LarryMac" <la********@msn.com> schrieb im Newsbeitrag
news:dd*************************@posting.google.co m...
This is sort of a newbie question, but it's making me crazy.

I have a project (VB.Net) in which data is read from a source file.
That data is used to create instances of the class "OrderItem" and a
list box (Supplies) is populated with those items. This part works.

If the user double-clicks an item on the list box, it checks to see if
that item appears on another list box (On Order) to see if it has
already been ordered.

Normally, I just cast the item on the list as a string
(CStr(lstSupplies.Items(lstSupplies.SelectedIndex) ) and search the
other list box for it, but this time I can't seem to cast an
"OrderItem" as a "String". I'm assuming it's because my collection is
objects and not just text strings, but I can't seem to come up with a
workaround. BTW, items are listed (sorted) by their description via a
ToString function within the class.

Any and all help is appreciated.

Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Alex Stevens | last post by:
I'd already posted this in microsoft.public.dotnet.framework.windowsforms and microsoft.public.dotnet.framework.windowsforms.controls to no avail so apologies for the cross-posting. Hi, I'm...
2
by: Peteroid | last post by:
I'm going to be using a ListBox in my managed C++ application, and have a question. Why are the Items you Add to a ListBox in the form of generic Object*'s? I believe a ListBox displays a table of...
1
by: tim payne | last post by:
Hi, I have a quick .Net question. When referencing a web control in my code behind page so that I can access it's methods and properties, is there any speed/efficiency bonus to using the fully...
2
by: Allan Horwitz | last post by:
When I try to reference the lstproducts.selecteditem.value using autopostback from the lstproducts listbox I get an error? How can I fix my code to get the selected value from the lstproducts...
0
by: antonyliu2002 | last post by:
I am not new to programming, but I am new to VB .NET. I have a multiselect listbox like this: Please select your favorite fruit: Apple Banana Coconut Date
2
by: Terry | last post by:
What is the syntax for referencing the properties of objects within Collections of objects? EXAMPLE: Dim MCoil As New Coil MCoil = CoilCollection("3456") TextBox1.Text() = MCoil.CoilDesc ...
6
by: Paul | last post by:
Hi All, Framework 1.1 listbox control unable to DataBind I've been googling for an answer to this query that appears quite a lot, but none, it seem, answers my problem directly. I am...
2
by: HankD | last post by:
Hi, I am having a problem with instantiating two custom objects so they DO NOT point to the same memory location. What is happening is that changes I am making to my object1 are changing object2. I...
2
by: wbosw | last post by:
I have a Arraylist (SearchSkillsArray) that contains objects. I want to place those objects into a listbox. Here i'm using get enumerator to loop through the arraylist and add the objects to the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.