bindinglist

Has anyone written a thread-safe BindingList<T>?

I am currently getting exceptions when modifying an IBindingList on multiple threads. Does anyone have a threadsafe version before I write my own? ...

DataGridView sort and e.g. BindingList<T> in .NET

Hi Folks I'm using a BindingList<T> in my Windows Forms that contains a list of "IComparable<Contact>" Contact-objects. Now I'd like the user to be able to sort by any column displayed in the grid. There is a way described on MSDN online which shows how to implement a custom collection based on BindingList<T> which allows sorting. But ...

Get the Enum<T> value Description

Hi there, I have my enumHelper class that contains these: public static IList<T> GetValues() { IList<T> list = new List<T>(); foreach (object value in Enum.GetValues(typeof(T))) { list.Add((T)value); } return list; } and public static string Description(Enum value) { Attribute DescAttribute = LMIGHelper.GetAttribute(v...

DatagridView + Custom Object binding

I have a datagridview in .NET 3.5 needs to display the following columns : ID, Name, ID2, Name2 This datagridview is binding as follows : BindingList source = new BindingList(); source.Add(new Class1 { ID = "1", Name = "Test", Class2Ref = new Class2 { ID2 = "Class2 ID" , Name2 = "Class2 Name"} }); dataGridView1.DataSource = source; p...

ObservableCollection(Of T) vs BindingList(Of T) ?

Hi, I've developped some data based Winforms Application this last two years and all works fine. This application are built on layers (DataAccess, Business Logic and UI). For the Businness Logic, all my objects inherit from a base class called BaseEntity with the following definition (there are some custom objects and interfaces, combin...

Why aren't classes like BindingList or ObservableCollection thread-safe?

Time and time again I find myself having to write thread-safe versions of BindingList and ObservableCollection because, when bound to UI, these controls cannot be changed from multiple threads. What I'm trying to understand is why this is the case - is it a design fault or is this behavior intentional? ...

Reordering items in BindingList in C#?

How would I move items in a BindingList in C#? Say, move last added item to the front, or swap with previous item? ...

InvalidOperationException on Databinding when removing last item in list.

I'm getting the following message when I try to remove the last item in a datagridview. DataBinding cannot find a row in the list that is suitable for all bindings. I have my binding setup as follows. ExtendedBindingList<MyClass> bl = new ExtendedBindingList<MyClass>(GetDataFromDB()); BindingSource bs = new BindingSource(); bs.Dat...

C# BindingList

Hi, I have a BindingList of type User, the User object has several properties (UserName, Password, etc). So I tied an event handler to the BindingList.ListChanged event, and it works fine when adding or deleting a user, BUT, if a user property changes, it does not raise the event, is there any way to achieve this? bindingListUsers.Add(s...

Can the DataDource of a BindingSource be a property from and object on the form.

For example: I have an Contact object on the form (see below). Can i set the datasource propery of the BindingSource to be the property Contact.Addresses. The class AddressCollection implements BindingList so there is no issue binding this when not encapsulated by the Contact class. public class Contact : IComparable<Contact>, ICompone...

Why does BindingList throw a System.ArgumentException when adding a member

I've got a binding list, that under certain hard to reproduce conditions is throwing the following exception when a value is added to it: System.ArgumentException: Complex DataBinding accepts as a data source either an IList or an IListSource. at System.ComponentModel.ReflectPropertyDescriptor.SetValue(Object component, Object valu...

BindingList<T>.Sort() to behave like a List<T>.Sort()

I am attempting to write a SortableBindingList that I can use for my application. I have found lots of discussion about how to implement basic sorting support so that the BindingList will sort when used in the context of a DataGridView or some other bound control including this post from StackOverflow: http://stackoverflow.com/questions...

Why can i not cast an IEnumerable<T> list to a BindingList<t>?!

Hi There, Is it possible to cast an IEnumerable list to a BindingList collection? The IEnumerable list is a list of typed objects e.g: IEnumerable<AccountInfo> accounts = bll.GetAccounts(u.UserName, u.Password); And my PagingList just extends BindingList: public class PagingList<T> { public BindingList<T> Collection { get; set...

BindingList memory leak

Hi All My application uses a custom List that inherits from Bindinglist which is then bound to all the UI controls. The list is a collection of baseobjects which implements INotifyPropertyChanged. I suspected a memory leak and profiled my application using memprofiler which confirmed that that all my lists are never disposed and that t...

Creating a custom collection that can be bound to a DataGrid

I work for an Architecture firm and I am creating a plug-in for a 3D modeling program to assist design. I have a Building class, and a Floor class. The building contains a reference to a FloorList collection of floors. I'm trying to figure out what to base the FloorList collection off of so that I can minimize the amount of work I need t...

Where / When / How does BindingList<T> convert / wireup PropertyChanged to ListChanged event

Hello all, I have a hierarchy of objects that all implement INotifyPropertyChanged. I also have a custom list that derives from BindingList. It is my understanding that when I add an object that impelements INotifyPropertyChanged to the list, that somehow the PropertyChanged event is automagically wired-up / converted to the ListChange...

From DataTable to BindingList

I am in the process of switching over from DataTable to BindingList. I bind the DataTable to the DataGrid object. Here my dilemma: while I certainly see the advantages of switching over, my circumstances will make it a bit complex and I am wondering whether it is worth it to switch over. My scenario: I have a DataGrid which displays c...

BindingList and column flexibility

Everyone raves about BindingList in place of DataTable. How do you guys overcome the problem of column flexibility? For BindingList I need to define and implement T object. If any new columns needed to be added, I need to add new properties to T object....while in DataTable this is much easier. BindingList<T> samples = new BindingList...

Binding to BindingList<T> - choose what to bind?

Say I have an business object called Sample and I have BindingList of Samples. A sample has 4 properties. Can I select which properties are bound to DataGrid or there no option to customize such a thing? NOTE: I am using Compact Framework, where is NO DataGridView, as well as Autogenerate property and DataMember property. Please keep...

Solution to the lack of covariance with generics in c# 2.0 (BindingList)

It's a design question. I have a business object, and 5 business object types that are derived from it. I also will have a class which has BindingList as a member. I will have 5 classes derived from it. Since covariance doesn't work here, how would you structure the design to minimize code repetition? I could of course chuck the Bind...