 |
|
 |
Has anyone looked into implementing 'Find' (of IBindingList)?
|
|
|
|
 |
|
 |
Hayder,
How could I use this implementation for an asp.net application?
Thanks for your help.
Colin
|
|
|
|
 |
|
 |
Hello. This code is GREAT! I spent all day trying to figure out how I could sort and filter a collectionbase I had bound to a DataGridView, and then I found this article and it saved the day!
My only question is, is there a change I can make so that when I filter string properties the filter will not be case sensative?
Thanks,
Joe
|
|
|
|
 |
|
 |
Does Anyone has VB.Net Version?
|
|
|
|
 |
|
 |
Nice article ! And source too !
I'm looking for a implementations of custom collection that support data binding at design time. But one step forward from just creating IComponent implementation in collection class. My question is : Is anybody created implementation for custom collection class that suport hierarchical data binding at design time ? Let me explain my question on the next example, using terms from MS Northwind sample. I have a collection of objects of type Order, and every Order object has a property OrderDetails, which is a collection of OrderDetail objects. I wish to create Master-Detail form with two datagrids, one bound to Orders collection, and other bound to LineItems collection of Order selected in the first grid (equal to using DataSet containing Orders and OrderDetails tables with relation between them). I need a solution for NET 1.1
|
|
|
|
 |
|
 |
When I try to serialize or use in WebService I get errors due to MustInherit. Any ideas?
::
Microsoft (R) Visual C# .NET Compiler...blah...
...
error CS0144: Cannot create an instance of the abstract class or interface 'CustomCollection.CustomCollection'
Belch
|
|
|
|
 |
|
 |
Hi,
I am facing the same problem. Previously I used to have custom collections inheriting from just collectionbase and i could mark the standalone object and the collections object as serializable and could store it in viewstate of my page. I tried to make my standalone object inherit from the BaseObject and my Collections inherit from CustomCollections object i face this error when I try to load my Object in the ViewState which says I need to mark my collections object as Serializable (which I have done). I dug a little deep into the problem and found that we might need to create a custom type convertor Attribute class with which I need to mark all the interfaces implemented by the class. Unfortunately ICloneable, IEditableObject and IBIndingList are all framework interfaces and I suspect one or more of them are the problem here dont know how to get past them.Somebody please advise on the fix to this problem.
Regards,
Ashwin
|
|
|
|
 |
|
 |
My guess is that because the CustomCollection(Base) is Abstract/MustInherit, and it cannot be instantiated even from within itelf (makes sense). This is what its doing when it creates a copy of itself for FilteredItems, etc. which does break the XML Serialization rules because the CustomCollection is Abstract.
I also run into a second issue with Event notifications of the list items. I had to re-bind after every change to see changes in a grid. Not good and not sure why (possibly due to the fact the InnerList does not spawn On* Events).?
I have not had time to try this but my guess would be that anywhere you try to use CustomCollection Object within itself or a related object (Filter.ApplyFilter(), etc) you should use ArrayLists instead?
Any takers?
Belch
|
|
|
|
 |
|
 |
I haven't try with XML Serialize but in binary serializing, I 've face this problem. I mark some field implemented by BaseList:
ListChangedEventArgs and EventHandler
as NonSerialized and it works.
|
|
|
|
 |
|
 |
Hi,
I am getting the same exact problem. When I try to put a CustomCollection inherited class into ViewState I get the serialization problem! Even when I try putting a BaseObject inherited class which contains a member (property) of type CustomCollection (example Order Class which contains a property CustomCollection OrderDetails. Removing this property gives me no problems.
I was wondering if you or anybody had solve this issue!
Thanks
Patrick
|
|
|
|
 |
|
 |
I think Parent property in BaseOject and cyclic reference(DeletedCollection & FilteredCollection) of CustomCollection object in Customcollection class are causing the problems.
-- modified at 15:52 Thursday 23rd February, 2006
|
|
|
|
 |
|
 |
Update this in BaseObject class.
[XmlIgnore]public CustomCollection Parent
Above statement solved the serialization problem.
Is XML Serialization is not able to serialize the abstract class??
Srinivas
|
|
|
|
 |
|
 |
I redid the Custom collection to inherit directly from the following:
ICollection, ISerializable, ICloneable, IBindingList
I then created and managed the innerlist via an array list. You still have to manualy create the implementations for the ICollection methods. You then mark the Customcollection class and BasObject Class as Serializable.
Include the follining method in any collection you create.
//Required to allow for deserialization
public (SerializationInfo info, StreamingContext context)
{
base.InnerList = (ArrayList)
info.GetValue("CustomCollection_InnerList", typeof(ArrayList));
}
I am now able to serialize using the binary formatter or XML serialization.
|
|
|
|
 |
|
 |
Here is the origin code (IList.Add) public void Remove(object value) { this.DeletedItems.Add(value); int index = IndexOf(value); BaseObject obj = (BaseObject) value; obj.Parent = null; InnerList.Remove(value); OnItemDeleted(new System.EventArgs(), index); if (! this.IsFiltering ) OnListChanged(new ListChangedEventArgs(ListChangedType.ItemDeleted, index)); } As you can see, we call IndexOf(value) whether we want to delete element, or simply filter it. The solution is: public void Remove(object value) { if (! IsFiltering) this.DeletedItems.Add(value); BaseObject obj = (BaseObject) value; obj.Parent = null; InnerList.Remove(value); if ((!this.IsFiltering )&&(!_updating)) { int index = IndexOf(value); OnListChanged(new ListChangedEventArgs(ListChangedType.ItemDeleted, index)); OnItemDeleted(new System.EventArgs(), index); } } You can see here new variable _updating. private bool _updating = false; public void BeginUpdate() { _updating = true; } public void EndUpdate() { _updating = false; } You should call BeginUpdate if you want "to switch of events" (for example if you are filling large collection on initializing and there is no reaseon to fire events) And also I changed IList.Add method public int Add(object value) { ((BaseObject)value).Parent = this; int i = InnerList.Add(value); if ((!this.IsFiltering )&&(!_updating)) OnListChanged(new ListChangedEventArgs(ListChangedType.ItemAdded , IndexOf(value))); return i; } P.S. You can check my improvements by means of .NET profiler. I used ANTS Profiler.
|
|
|
|
 |
|
 |
Nice Idea.
??????
You can check my improvements by means of .NET profiler. I used ANTS Profiler.
?????
|
|
|
|
 |
|
 |
https://www.red-gate.com/products/ANTS_Profiler/index.htm
|
|
|
|
 |
|
 |
There is a problem with CustomCollection.Clear. It does not remove the last element.
|
|
|
|
 |
|
 |
Try this one:
public new void Clear()
{
for(int i= this.Count-1 ; i>=0 ; i--)
{
this.Remove(this[i]);
}
}
|
|
|
|
 |
|
 |
Actually I made something like this:
public new void Clear()
{
InnerList.Clear();
OnListChanged();
}
|
|
|
|
 |
|
 |
It run faster and faster.
But I used the Getchange() method and if the Clear() method doesn't add any thing to the DeletedItem, I can't get deleted object from the Collection
|
|
|
|
 |
|
 |
Well, then youn can use DeletedItems.AddRange(items []). It works much faster then simple Add(item).
|
|
|
|
 |
|
 |
CustomCollection contains DeletedItems and DeletedItems also contains DeletedItems and DeletedItems.DeletedItems contains DeletetedItems and so on. So, where is the end?
Here is my solution
private ArrayList deleteditems;
public ArrayList DeletedItems
{
get
{
if (deleteditems == null)
{
deleteditems = new ArrayList();
}
return deleteditems;
}
set
{
deleteditems = value;
}
}
internal ArrayList filtreditems;
public ArrayList FiltredItems
{
get
{
if (filtreditems == null)
{
filtreditems = new ArrayList();
}
return filtreditems;
}
set
{
filtreditems = value;
}
}
|
|
|
|
 |
|
 |
Of course. There is no reason to DeletedItems and FiltredItems to be typed as CustomCollection. And i suppose that it increase permormance too when filtering.
|
|
|
|
 |
|
 |
I've modifide ur code 2 decrease reflection calls and 2 increase performance.
public object ApplyFilter(object objToFilter, string StrFilter)
{
try
{
CustomCollection ObjectToFilter = (CustomCollection)objToFilter;
int CountValue = ObjectToFilter.Count;
Expressions ListOfExpressions = new Expressions(StrFilter);
//Loading items of the collection
bool [] Validations;
bool AllIsOK;
int cicle = 0;
for (int f = 0; f<= (ObjectToFilter.Count -1; f++)
{
object CollectionItem = ObjectToFilter[f];
Type TypeOfItem = CollectionItem.GetType();
Validations = new bool[ListOfExpressions.Count ];
AllIsOK = true;
for (int t = 0 ; t<= ListOfExpressions.Count -1 ; t++)
{
DateTime timeSt1 = DateTime.Now;
PropertyInfo[] list = TypeOfItem.GetProperties();
PropertyInfo ItemProperty = TypeOfItem.GetProperty (ListOfExpressions.Item(t).PropertyName,BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase );
if( ItemProperty == null)
{
throw new Exception ("property " + ListOfExpressions.Item(t).PropertyName + " does not exists!");
}
object PropertyValue = ItemProperty.GetValue(CollectionItem, new object[0]);
if (PropertyValue ==null)
{
Validations[t] = IsOk(ListOfExpressions.Item(t).Operator , ListOfExpressions.Item(t).UserValue );
}
else
{
Validations[t] = this.IsOk(PropertyValue, ListOfExpressions.Item(t).Operator , ListOfExpressions.Item(t).UserValue );
}
if (Validations[t] == false)
{AllIsOK = false;}
System.Diagnostics.Trace.WriteLine("time : " + (DateTime.Now - timeSt1).TotalMilliseconds.ToString() + " cicle : " + cicle.ToString());
timeSt1 = DateTime.Now;
cicle++;
}
if (AllIsOK == false)
{
ObjectToFilter.Remove(CollectionItem);
ObjectToFilter.filtreditems.Add(CollectionItem);
CountValue -= 1;
f -= 1;
}
}
}
catch(System.Exception ex)
{
throw ex;
}
finally
{
}
return new object();
}
|
|
|
|
 |
|
 |
so, what do u think about it? Why should we use reflection if we know that parent was CustomCollection?
|
|
|
|
 |