LinqBindingList<T> Adding item to list?

LinqBindingList<T> Adding item to list?

Old forum URL: forums.lhotka.net/forums/t/7363.aspx


Brette.Net posted on Wednesday, July 29, 2009

In reading about the LinqBindingList<T> it states.

"adding an item to a LinqBindingList adds the item to the original list as well as any other LinqBindingList"

This is true however when I first do an orderby("Id Asc") then later attempt to add a new item to the LinqBindingList collection the item is added to the source '_list' yet the '_filterIndex' remains unchanged. It seems strange that an OrderBy would effect this. I would expect both lists to get the newly added item since there was no filter criteria that would exclude this.

Has anyone encounterd this?

Brette

 

AaronErickson replied on Thursday, July 30, 2009

I will create a test to try to re-create this, but I am working at a client right now so it will probably be a couple days.

I can state that if you are doing an orderby operation, the result of the orderby should be a new LBL that retains the properties of all LBL collections that are generated from the original BLB.

In the interim, maybe try the non-Dynamic Linq version? (use .OrderBy(item => item.Id); and see if that works?

Brette.Net replied on Thursday, July 30, 2009

Thanks for the reply. To help you in your sample here is what I am doing.

//When ourWPF Screen loads.

OperationList = BusinessObject.Operations.OrderBy(operation => operation.OperationName) as LinqBindingList<AssociatedOperation>;

The OperationList is then bound to a ListView. When the add button is clicked the following code is executed.

OperationList.Add(Operation.Create());

At this time the _list shows the newly added item but the _filterIndex does not. In order to get it to work I have to do the following.

//Add Item to list

BusinessObject.Operations.Add(Operation.Create());

//Recreate LinkBindingList

OperationList = BusinessObject.Operations.OrderBy(operation => operation.OperationName) as LinqBindingList<AssociatedOperation>;

This is not a horrible solution but it does not seem right.

Thanks,

Brette

 

Copyright (c) Marimer LLC