.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Problem when adding items to a listbox from different threads

Posted By:      Posted Date: September 22, 2010    Points: 0   Category :WPF

I have an application in which different threads add items to a listbox throughout the application's execution (not at startup). But when one of the threads tries to add an item to the listbox, a System.InvanlidOperationException is thrown and the error message is: "The calling thread cannot access this object because a different thread owns it." (In my scenario the "calling thread" is one of the worker threads that add items to the listbox, and the "different thread" is the UI thread.)

So basically I just need a simple way to allow the threads to share the listbox object, or, failing that, some other workaround.

View Complete Post

More Related Resource Links

Adding Items to ListBox with animation



I have the following code:

<DataTemplate x:Key="DataTemplate1">
		<EventTrigger RoutedEvent="FrameworkElement.Loaded" SourceName="textBlock">

Adding Items to ListBox Dynamically

How to add list box item dynamically? Each list box item should be a stack panel which has an image and a label. Image and label for the item is known only in the runtime. How to achieve this?

This sharpoint 2010 problem solving threads

Hi friend,

you can use this thread to solving problem and solutions.

Adding new items to a Repeater control with transitions?



I am currently in the process of writing a facebook type 'activity feed' for a site. Currently I am binding the last 10 items to a repeater control, which contains a usercontrol representing each item. This works fine but there are a couple of requiremnts that are giving me problems and wondered if the the good people of the forum could make some suggestions.

The requirement is that when a user clicks a refresh button any new events are added to the top of the list, the previous items drop down and the equivalent number of old items drop off the bottom, all with nice slider transitions.

I have put the repeater inside of an update control and are able to handle the transitions by using RegisterStartup script to drop jquery calls onto the page for the slider. However I cannot find a way to dynamically add or remove new datarows to the repeater. I need the old items to stay in the repeater and be pushed down by the new items, so completely refreshing the datasource seems like a bad idea.

I was thinking about maybe storing the datasource in the viewstate and adding rows to that, maybe with an extra column on the end which stores what transition is needed on the databind for my jquery, but there will be a 'View more items' link at the bottom of the page, so I am worried that the list could get pretty large and there

Way of adding items in Drop Down List or List Box using Javascript

The article Way of adding items in Drop Down List or List Box using Javascript was added by raja.s on Sunday, June 06, 2010.

Hi,script type="text/javascript"> function AddItem(Text,Value) { // Create an Option object var opt = document.createElement("option"); // Add an Option object to Drop Down/List Box document.getElementById("DropDownList"

Items.Remove or RemoveAt Problem


Hi Guys,

I have this issue i have been looking at for a while and cant seem to figure it out. I have two ddl's on my page and a InsertCommand from sqldatasource. My InsertCommand is actually updating the foreign key of the two ddl's in another table. When i click on my button it shows two numbers instead of one.

The challenging thing now is that i have


after the insert so it would not duplicate what i am updating. If i take this statement out of my code. it updates well as in showing the one record that was updated. if i put it back in there it shows two records where updated. I tested my sql statement and its working fine meaning it shows only one record is updating. Could you possibly know whats wrong.

Thanks in Advance

Problem adding it to my project.


I tried to add Modal Popup to my project. I tried the Sample Site, it worked there, when I added it to my toolbar, and followed the tutorial, I couldn't use it. Then, I tried something simplier just to test, I added a Confirm Button, when I try to execute the page it goes back to Visual Studio and show me this:

Locating source for 'd:\hg\act\Server\AjaxControlToolkit\ExtenderBase\ExtenderControlBase.cs'. Checksum: MD5 {56 64 14 a8 4c 29 25 94 27 e0 35 10 f1 b4 60 f2}
The file 'd:\hg\act\Server\AjaxControlToolkit\ExtenderBase\ExtenderControlBase.cs' does not exist.
Looking in script documents for 'd:\hg\act\Server\AjaxControlToolkit\ExtenderBase\ExtenderControlBase.cs'...
Looking in the projects for 'd:\hg\act\Server\AjaxControlToolkit\ExtenderBase\ExtenderControlBase.cs'.
The file was not found in a project.
Looking in directory 'C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\crt\src\'...
Looking in directory 'C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\atlmfc\src\mfc\'...
Looking in directory 'C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\atlmfc\src\atl\'...
Looking in directory 'C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\atlmfc\include\'...
The debug source files settings for the active solution indicate that the deb

Video: Adding SharePoint 2010 Project Items to a C# or VB.NET Project

Each project is either a C# or VB.NET project that contains particular initial project items. In addition Visual Studio 2010 includes SharePoint project items that you can add to any of your projects. (Length: 18:53)

How to create a dynamically populated items in a listbox and use it as a navigation?

Hello, I am trying to create navigation inside a listbox menu. I load data from xml to populate a list. Each item in the list box should be a link or button. Then, I create a frame to load xaml pages in it. I tested to load pages employing button control, outside listbox with on click event and it worked well. However, I cannot make it work with list box items. I am hoping to get help from you. Any sample or ideas are highly appreciated. Below is the code:  XML: <?xml version="1.0" encoding="utf-8"?> <Pages> <page id="page01"> <name>Page 01</name> </page> <page id="page02"> <name>Page 02</name> </page> </Pages> C# to initiate a click o n listbox item and get the path to page: private void SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e) { ListBoxItem lbi = ((sender as ListBox).SelectedItem as ListBoxItem); string itemName = lbi.Content.ToString(); if ( Nav_ListBox.SelectedItem.Equals("Page01" ) ) { ContentFrame.Source = new Uri("Pages/Page01.xaml", UriKind.RelativeOrAbsolute); } } XAML:  <ListBox x:Name="Nav_ListBox" Margin="0" ScrollViewer.HorizontalScrollBarVisibility="Hidden" Background="#FFF2F2F2" ItemTemplate="{DynamicReso

Problem adding .NET 3.5.1 feature on Server 2008 R2

Having an issue with a 2008 R2 64-bit Server becoming unresponsive/locking up when trying to activate the .NET 3.5.1 feature.  Did not have any previous version of .NET installed but ran the .NET Cleanup utility and completed successfully but still have same issue.  It installed .NET 4 via the Microsoft Updates OK but still hangs part way through the 3.5.1 install via the Server Manager/Add Features.  Any ideas?  Thanks!

Adding items to ObservableCollection via DataGrid

Hi All, I have a DataGrid bound to an ObservableCollection. I'd like to be able to add objects to the collection via the Grid. When I was working with sample data, I could go to the bottom of the grid, hit enter and add a new entry. Now that I'm using real data I don't seem to be able to do that. I tried taking a look at the class that the SampleData creates and can't quite fathom what it's up to. Does anyone know what I'm missing \ what I need to implement to make this possibe? Thanks Warrick

Animate listbox items from ItemTemplate

I want to have a slide-in effect for listbox items, when it's first loaded. I'm using ItemTemplate for listbox items and I coule do the slide-in effect from within the template using RenderTransform and DocubleAnimation. but as the Listbox is vertualized, it does the effect everytime new page of data is loaded in listbox. What I want is to animate the visible items in listbox only when DataContext is changed the first time, like messages list in 'Windows Live Mail' thanks in advance.  

Adding, removing or editing the items of combobox.....

Hello everyone, I am working on this application which requires Items of the combobox added, edited or removed by the end user in the different section of the application such as settings window or something like that. I guess If we bind the Combobox to the database where we could easily add , remove or edit the items of combox but for the application that doesn't use database that creates a lot of overhead. To demonstrate that Here is my sample application Window1.xaml <Window x:Class="MySampleApplication.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" Title="Window1" Height="300" Width="300" xmlns:local="clr-namespace:MySampleApplication" ResizeMode="NoResize" WindowStartupLocation="CenterScreen"> <Window.Resources> <local:StringsLenToBooleanConverter x:Key="mvc"/> </Window.Resources> <Grid> <ComboBox Height="26" Margin="12,75,12,0" Name="comboBox1" VerticalAlignment="Top"> <s:String>Red</s:String> <s:String>Blue</s:String> <s:String>Green</s:String> </ComboBox> <Button Height="28&quo

In a group calendar, can items be made visiable to all users by default without adding them as atten

Well the title says it all really. We have a functioning sp 2010 site, setup this weekend, that's working great so far.  Primarily its being used for the company manual and procedures (a wiki site).  Search is working well and so on. I added a calendar with the intention of showing key company activities, plus holiday information and who's out at meetings.  We're a small company and this is unlikely to get ridiculously except on exceptional days. As it stands, when i create an item (for example someone out for a weeks holiday) unless another user adds one of the 'attendees' of the holiday event to the calendar it doesn't show up.  If I add all users as attendees then they can all see it by default. However, if I show that our chairman is attending a meeting at a client, then I can't explicitly say that the chairman is an attendee because for everyone to see it, they have to be attendees as well. I nsoed around a little and thought target audiences might be the way to go.  I configured all users and manager relationships, compiled the audience (it shows the right number of users).  However, if I setup a meeting with the chairman as an attendee, and the whole company audience as the target audience, then people still can't see it. Back to square one. So, is there an actual answer to this?  A different type of calendar, a query that

Selecting Items in a databound ListBox

Hi All, I'm facing a problem while trying to programatically preselect few items in a databound ListBox. I have set the datasource of the listbox to a DataTable, with required Data and Value member columns. The selection mode of the listbox is MULTIEXTENDED. Platform: .NET  1.1 (not sure if the problem is relevant to other versions) I tried preselecting items in a different ListBox that is not bound to any datasource. I'm able to preselect items using the SetSelected method. Perfect!   How can I achieve the same for a databound ListBox? What am I missing? Any help will be very much appreciated.   Regards, Amirtha

Reverse Superscript for Listbox Items in C# windows

I want to show Reverse Super script formate for Listbox Items when i check CheckBox using c# windows forms. thanks ram

problem with displaying items in list view web part

I have a list view webpart at default display form. Default Display form display items (for example) from the contracts documents library. List view webpart also associated with the same documents library (contracts). In such case this webpart doesn't display any item. But if I add another list view web part associated with warrants document library it display item without any problems. Is it possible to bind list view webpart to another data source for contracts document library? Or maybe another solution? Thanks!
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend