Wrox Programmer Forums
|
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 15th, 2003, 05:25 AM
Registered User
 
Join Date: Jul 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Saving Listbox Items

Hi,

2 questions...

1) i have a list box control with multiple items selcted which i ma trying to save to a database with a stored procedure. But only the first slected item ever gets saved. I am using the .selecteditem.value option. How do i get all the selected items to pass.

2) i have 2 list boxes. List box 1 passes items to listbox 2. I now need to pass the items in listbox 2 to a database, but i cannot make it work because noting is selected. How do i pass the listbox 2 items without having to select them individually.

Someone please help

Thanks

Anton

 
Old July 16th, 2003, 12:46 PM
Authorized User
 
Join Date: Jul 2003
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Either way, to get multiple selected items into anything else (a file, a DB, etc) you need to treat your list as an array (which it actually is) and iterate all the items in the list using a For-Each loop, testing to see if .selected = true for each item....

example below is looking for selected items in a listview control (listviewitem) but just change it for a listbox control (listitem I think) (see vb.net help):

Private Function GetQName() As String
        '//strip q name
        Dim qName As ListViewItem
        For Each qName In lvwQueues.Items
            If qName.Selected = True Then

                     '// do push to database here

            End If
        Next
        qName = Nothing
End Function


The above is from a program I wrote for work, dealing with lists of message queues in a listview control. You can use the above as a guide just make sure your iteration object matches the control (listbox = listitem i think) see vb help.

hope this helps
James





Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting all listbox items Lucy_H85 C# 2005 2 December 1st, 2009 05:36 AM
unselecting items in a listbox Durkee VB.NET 2002/2003 Basics 9 October 8th, 2007 03:01 PM
Moving Items up and down in a listbox Brendan Bartley Access 15 September 18th, 2007 06:42 AM
Error in Saving Ordered Items newbie_inasp2.0 BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 6 August 22nd, 2007 05:11 PM
UNSelect Items in ListBox mmcdonal Access VBA 7 June 21st, 2007 08:09 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.