observablecollection

How does ObservableCollection work?

I was having a look at the ObservableCollection code (thanks to the awsome .NET Reflector) and was surprised to find that the Add and Remove methods are not overriden. How then does ObservableCollection raise the PropertyChanged or CollectionChanged event to notify when something is added or removed? ...

Make copy of sorted wpf DataGrid

Need help. myCollection = new DB.PersonCollection(); dGrid.ItemsSource = myCollection; User must sort DataGrid and then use sorted data to make report. How to take exact copy of DataGrid-layer collection (with sorted items) ...

WebService: How to return an array of a complex type?

2 Questions really, and I'm not sure if I'm doing this right or not... I want to send back an array of some sort for an Entity object I created. I'm not really sure how to mark it for sending (what attributes are needed or whatever), and I'm not really sure how to send it back (IList, List, Collection, ICollection). Ideally I'd love to...

Search an ObservableCollection by its objects fields.

Hello. I'm developing a Windows Phone application with C#. I have an ObservableCollection defined as follows: public class StartingPersons { public string ImagePath { get; set; } public string Name { get; set; } public static ObservableCollection<StartingPersons> GetPersons() { ... } } I want to search i...

ObservableCollection auto-index

I've got a list of items that I'm placing in an ObservableCollection which I am then databinding to a datagrid UI created in XAML. One of the columns displayed is the index of the item in the list. Currently, I am creating a property and binding to it. However, this creates a lot of work when I need to update/add/remove items from the li...

Binding ContextMenu on flattened ViewModel

Hi, suppose the following classes: public class Model { public ObservableCollection<A> Items { get; set; } } public class A { ObservableCollection<B> Data { get; set; } //... some more properties } public class B { //..properties } The model is bound to a RibbonMenu and should also be used in a context menu. The co...

Update a ObservableCollection with a background worker in mvvm

Ok, I recently implemented a background worker to perform saves and loading of data. However getting this to work on a save command has proved difficult. Basically my Save command generates an event that notifies a collection view model that an Item has been added and that It should add it to its own observeablecollection. At this poi...

How To Prevent WPF DataGrid From De-Selecting SelectedItem When Items Updated?

My scenario: I have a background thread that polls for changes and periodically updates a WPF DataGrid's ObservableCollection (MVVM-style). The user can click on a row in the DataGrid and bring up the "details" of that row in an adjacent UserControl on the same main view. When the background thread has updates, it cycles through the ob...

Null items not shown in ComboBox with binding

Hello, I'm having some difficulties with null and a ComboBox in WPF/C#; If a add a null item it is not shown/listed in the ComboBox. Here is de XAML declaration of my ComboBox <ComboBox ItemsSource="{Binding Path=MyList}" SelectedItem="{Binding Path=Type}" /> MyList is declared as public ObservableCollection<Type> MyList...

Binding ObservableCollection<Foo> to ObservableCollection<object>

I have a collection ObservableCollection<Foo>, and I want to bind this to a property in a custom controller of type ObservableCollection<object>. However, the bound value never reaches the PropertyCallback, and is hence never set. Is there a clever way to achieve this binding? I could create an IValueConverter that converts from Observ...

dynamic binding of rows and columns to a grid in WPF

With a DataGrid object in WPF, we can bind its rows to an observable collection such that as rows are added or removed to/from the collection, the UI updates to display the changes. I am looking to do something similar with a Grid control as part of a User Control I am trying to create. Is this possible? ...

xamdatagrid and observable collection refresh

Hi, i have simple master detail in wpf with listbox filled in with Order object and Xamdatagrid with OrderDetail. Listbox`s Itemsource is bound to the ObservableCollection defined in ViewModel. Xamdatagrid is also bound to the observablecollection defined in datagrid. If user click Order in the listbox i want to fill xamdatagrid with Ord...

Silverlight4 ObservableCollection and updates to database

Hi All, I have implemented the Drap n Drop functionality using the two listboxes (lstSource, lstDest) where user can drap & drop item between two lists. I have two ObservalableCollections (sourceCollection & destCollection) which are binded to the relevant lists. In the initial load method, DomainContext gets all the tasks from db and ...

WPF Datagrid Performance

I have a very large comma-seperated text-file. I need to display this in a WPF Datagrid, which method would result in the highest performance of loading all the data to the grid? I'm only aware of two methods: Using a Datatable, and adding each line as row (looks like overkill) Using an ObservableCollection, creates object for each lin...

What is the type of object added by IEditableCollectionView?

Adding objects with the IEditableCollectionView addNew() method is pretty decent. However I'm not sure how well it works with my generic code I have. I have a ObservableCollection of my base class. Depending on what the user wants to see it can be filled with DerivedA or DerivedB ( or mutliple other derived type classes ). It never has ...

Re-establishing WPF databinding after changing property value

I'm playing with ICollectionView right now, and am encountering a problem where I think I understand the "why", but not the "how do I fix it". :) I have a ComboBox that's databound to an ICollectionView, and it is initially set with the following code: NameView = CollectionViewSource.GetDefaultView( names); // names is an IEnumerable<...

Creating ObservableCollection from Inheriting DataSet for WPF Binding

Need: Need to bind data to WPF controls for a user to update a database. Approach: I am trying to implement a solution similar to this but am having an issue because I will be using a DataSet and not LINQ to SQL Class (hitting an Oracle db for my data). If this is a correct approach how can I do this? I'm also thinking instead of addi...

remove and inmediatly add the same UserControl to an ObservableCollection

Hi, I have 2 listboxs which ItemsSource is an ObservableCollection, but that throw an exception of "not valid value", for resolve that I made a wrapper class that have a property of type MyUserControl and I changed also the collection for an ObservableCollection changing also the ListBoxItemTemplate to a ContentPresenter with Content bi...

How to remove items from list x seconds after adding them

Hi. I need to remove items from list few seconds after i added them. I have now an ObservableCollection to which I add some messages. I need them to be deleted let's say 5 seconds after they were added. I tried to create a function responsible for adding the items and setting a timer: public void AddInfoItem(string info) { ...

WPF - How can I implement an ObservableCollection<K,T> with a key (like a Dictionary)?

I have used an ObservableCollection with WPF for binding and this works well. What I really want at the moment is a Dictionary like one, that has a key that I can use, so effectively like "ObservableCollection". Can you suggest the code that could be used to provide such an ObservableCollection? The goal is to have a Dictionary like s...