Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
|
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 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 2nd, 2007, 05:28 PM
Authorized User
 
Join Date: Jun 2007
Posts: 14
Thanks: 2
Thanked 0 Times in 0 Posts
Default select value in listbox please help urgent


i have two checkedlist box in windows form. i am adding some values from first checkedlistbox to second checkedlistbox using some button controls .

i am adding all the checked values at a time from the first to the second.

I would like to remove the values from the first at the same time it's been added to the second.

   string selectName=clAvailableColumns.SelectedItem.ToStrin g();
   int selectIndex = clSelectedColumns.FindString(selectName);
   if (selectIndex == -1 )
    {
       foreach (string item in this.clAvailableColumns.CheckedItems)
       {
               clSelectedColumns.Items.Add(item.ToString());
        }
    }

would be kind if anyone could help me..........


 
Old July 9th, 2007, 06:07 AM
Authorized User
 
Join Date: Dec 2004
Posts: 68
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to DZukiewicz
Default

This is the cleanest way I found of doing it. You can't do it with foreach loops as by removing an item, you are changing what you are iterating through. Its more of a safety mechanism than an error. This works both ways.

Code:
  private void SwapItems(ListBox source, ListBox dest)
        {
            while (source.SelectedItems.Count != 0)
            {
                dest.Items.Add(source.SelectedItem);
                source.Items.Remove(source.SelectedItem);
            }
        }
Regards,

Dominic





Similar Threads
Thread Thread Starter Forum Replies Last Post
Select the all itmes in listbox by pressing Ctrl+ gmbalaa General .NET 1 August 22nd, 2007 02:17 AM
Select an particular item when a listbox opens? alastair Access 2 December 29th, 2005 06:04 PM
select statement with listbox item(where qnsID =" Astro VB How-To 2 August 31st, 2005 02:12 AM
multiple select--Urgent muralikeane Classic ASP Databases 3 May 12th, 2004 07:00 AM
URGENT: automate - OPEN A FILE DIALOG BOX,SELECT chichi120976 Excel VBA 1 December 13th, 2003 05:22 PM





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