Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 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 November 13th, 2009, 04:00 PM
Authorized User
Join Date: Apr 2009
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
Default moving items from one listbox to another listbox

I have two listbox control on my C# windows application.
I need to move items from list1 to list2 and list1 is bound to database. (data in list1 is coming from database).

When I am trying to use following condition,


It is giving me an error, "Items collection cannot be modified when the DataSource property is set." Can anyone please help me?
Old December 1st, 2009, 05:01 AM
Friend of Wrox
Join Date: Nov 2009
Posts: 156
Thanks: 13
Thanked 16 Times in 16 Posts

I don't know that how you have bounded ListBox to database.
here is a good way to solve this problem. Imagine that our data is collected into a DataSet object named ds. define a DataTable like this:

DataTable dt = new DataTable();
dt = ds.Tables["your table name goes here"];

List1.DataSource = dt;
and when you want to delete from list1, you can delete data from dataTable object (dt) and automatically list1 is refreshed. Note that dt should be a global variable in class
Old December 3rd, 2009, 07:20 AM
Registered User
Join Date: Dec 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts


You can even try retrieving the data from the list box into a variable and then add it to another list box
Web Development Services

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
UNSelect Items in ListBox mmcdonal Access VBA 7 June 21st, 2007 08:09 AM
Unhighlight Listbox Items selevanm Access VBA 1 March 7th, 2007 01:39 PM

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