In Focus
Delhi Chapter Hands On June 22: Limited Seats Register Now
Kolkata Chapter Developer Day: May 25
C# Corner Delhi Chapter Meet, May-18, 2013 Official Recap
Istanbul Chapter May 2013 2nd Seminar Announced : Learn WinJS, Windows Store, MVC
Email :
Password :
Remember me?
Forgot password
Technologies
Monthly Leaders
ASK A QUESTION
C# Programming
Multi-threading
Microsoft Surface
Community Services
Java
.NET General
Office Interoperability
ReFS
Current Affairs
JQuery
Active Directory
Printing
Silverlight 5
Fun and Jokes
JSP
ADO.NET & Database
Project Management
WCF
Job Opportunities
Multimedia, Graphics, Flash
AJAX & Atlas
Remoting
Windows 8
Leadership
PHP
Algorithms & AI
Reporting
Windows Azure
Mac for Windows
Social Networking
Arrays & Collections
Robotics and Hardware
Windows Store Apps
Microsoft Feedback
TypeScript
ASP.NET & Web Development
Security & Cryptography
Workflow Foundation
Open Source Projects
Web Hosting
C# Language
Setup & Deployment
WPF
Operating Systems
Website Management
C# References
Sharepoint
XAML Language
Paid Projects
Windows Azure
CLR & .NET Internals
Speech & Voice Recognition
Site and Forums Feedback
Prizes, Awards, MVP
Windows Phone 7
COM Interoperability
Tablet PC
Announcements
Students & Beginner Projects
Database
Custom Controls
Testing and QA
Author Guidelines
Test Category
Database General
Design and Architecture
Visual Basic .NET
Bugs and Problems
Training & Certification
Oracle
Embedded Development
Visual C++
Forums Feedback
Web Development
SQL
Enterprise Development
Visual Studio 11
Site Feedback & Suggestions
Advertising, Marketing, SEO
SQL Server
Games, DirectX, and XNA
Visual Studio 2010
Site Spams
Android
Products
GDI+ and DirectX
Web Services
Miscellaneous
Cloud Computing
Office 2013
General
Windows Forms
.NET Books
Expression Tools
Products
LINQ
Windows Services
Ask the Author
HTML 5
SharePoint 2013
Migrating to .NET
Cutting-Edge
Career Advice
HTML, JavaScript, CSS
Windows 8
Mobile Development
.NET 5.0
Coffee, Chai Lounge
iPhone, iPad
Forum guidelines
Home
»
WPF
»
Move Item from bound Listbox to another bound Listbox
Author
Question
Steven Davisworth
Move Item from bound Listbox to another bound Listbox
Posted on: 13 Dec 2012
coldworkdraftucontrol.zip
Hello
I've created two lisboxes. One is bound to an ObservableCollection returning results from SQLight query. The code I have in place works great if listbox2 is not bound.
Basic senario is Listbox1 presents selectable items to populate listbox2. User dblClick listbox1 item and it moves to listbox2. Listbox2 is saved to DB... when the user opens the UI at any given time or even in same session, they should be able to remove items from lisbox2. NOTE (Listbox1 is filtered by whatever is in Listbox2 i.e no items can exist in two listboxes at any given time.)
Problem: As soon as I try and bind listbox2 I get error "Operation is not valid while ItemsSource is in use. Access and modify elements with ItemsControl.ItemsSource instead."
Code:
Listbox1 MouseDoubleClick -
ListBoxItem myListBoxItem =
(ListBoxItem)(listBoxCertificateLookup.ItemContainerGenerator.ContainerFromItem(listBoxCertificateLookup.Items.CurrentItem));
// listBoxCertificateSelected.DataContext = null;
listBoxCertificateSelected.Items.Add(myListBoxItem);
Listbox2 MouseDoubleClick -
ListBoxItem myListBoxItem =
(ListBoxItem)(listBoxCertificateSelected.ItemContainerGenerator.ContainerFromItem(listBoxCertificateSelected.Items.CurrentItem));
//listBoxCertificateLookup.DataContext = null;
listBoxCertificateLookup.Items.Add(myListBoxItem);
Listbox1 -
ObservableCollection<CertificateLookup> CertificateLookupList = new ObservableCollection<CertificateLookup>();
foreach (DataRow r in conditions.Rows)
{
CertificateLookupList.Add(new CertificateLookup()
{
Section = r["Section"].ToString(),
Description = r["Description"].ToString(),
SortOrder = r["SortOrder"].ToString()
});
listBoxCertificateLookup.DataContext = CertificateLookupList;
}
Listbox2 -
ObservableCollection<CertificateSelected> CertificateSelectedList = new ObservableCollection<CertificateSelected>();
foreach (DataRow r in conditions.Rows)
{
CertificateSelectedList.Add(new CertificateSelected()
{
selectedSection = r["Section"].ToString(),
selectedDescription = r["Description"].ToString(),
selectedSortOrder = r["SortOrder"].ToString()
});
listBoxCertificateSelected.DataContext = CertificateSelectedList;
... rest of code as attached.
Thanks in advance.
Reply
Quick Reply
Report a Spam
Our Recommended Solutions
Transferring data from one ListBox to another in WPF
Dynamic Update of ListBox in Windows Store App
Search and Delete Items in The ListBox In Windows Phone 7
Dynamically Add and Delete Items in ListBox Using ASP.NET
Bind Data in a ListBox in VB.NET
Adding items to a listbox in Expression Blend
Editable ListBox in C#
Databinding in Listbox from XML file
Working with Data Bound Controls
Adding Xml Data source in Wpf Application using Expression Blend
[ + ]
Author
Reply
Satyapriya Nayak
0
0
Re: Move Item from bound Listbox to another bound Listbox
Posted on: 13 Dec 2012
http://www.c-sharpcorner.com/uploadfile/mahesh/transferring-data-from-one-listbox-to-another-in-wpf/default.aspx
If this post helps you mark it as answer
Thanks
Reply
Quick Reply
Steven Davisworth
0
0
Re: Move Item from bound Listbox to another bound Listbox
Posted on: 14 Dec 2012
Thank you for your response
I've come across the above posting which I tried before, but am
not sure on how to apply data templates to that code so as to allow me to have columns filling up and then spilling over to second column and then third colomn etc. as items get added?
Apart from this the
general consensus is that I use an ObservableCollection
<ListBox Name="listBoxCertificatesLookup"
ItemsSource="{Binding Tables[0]}"
SelectionMode="Multiple"
IsSynchronizedWithCurrentItem="True"
MouseDoubleClick="DataTemplateFindElement"
HorizontalAlignment="Left" Width="300" Height="75" >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Height="23" Orientation="Horizontal">
<TextBlock Name="textBlock" Text="{Binding Path=Description}" VerticalAlignment="Top" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel IsItemsHost="True" Orientation="Vertical" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
Reply
Quick Reply
Quick Reply:
SEARCH ANSWERS
All
C# Programming
Cutting-Edge
Site and Forums Feedback
Miscellaneous
Web Development
Database
Products
Any Word
Exact Word
Our recommended forum posts
how to retrieve specific row from database in gridview?
in my grid view i place 1 dropdownlist fill with some items
Selected row from gridview to dropdown
Listview scroll bar - How do I know user has clicked listvie
Multiple Key Binding for Shortcut
Consume WCF wsHttpBinding/message/username service from asp.
Size Reduced for Images in PDF & Improved Images to PDF Con.
Popup search window
rotate touch based needles of windows 8 clock app
How to rotate touch based needles ( Hour and Minute ) of win
HOT QUESTIONS
Import/Export Generic List Objects
javascript for submit form without using submit button
Create List accessible for other classes
Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)
Extracting Data from a listbox in Another Application
mathematical euation
code is not working
how can i locate a webbrowser control
Congratulation Vinod Kumar
If company is giving wrong feedback about Emp then what should we have to do ?
SPONSORED BY
DynamicPDF ReportWriter Suite
PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.