Hello,
I have a collection of objects which implemepts IEditableCollectionView
In my AddNew i prepare the item i want to add to the collection .
Than i enter the indexer of the object i am adding and setting it's attributes (i have a dynamic XamGrid columns)
Than in my CommitAdd i add the prepared item to the collection.
I do it like this:
private Boolean _isAdding = false; public object AddNew() { _isAdding = true; return _attributeRow = new FilterSetDefinitionAttributeRowViewModel() { ParentViewModel = _parent }; return null; } private FilterSetDefinitionAttributeRowViewModel _attributeRow; public void CommitNew() { Add(_attributeRow); //Add(_attributeRow); _isAdding = false; } public void CancelNew() {
But after it's complete i get an exception saying "Parameter count mismatch." from MSCORLIB
Hello Michael,
Thank you for your post. I have been looking into it, but it seems like I am missing something about your scenario, so could you please send me an isolated sample project, where this is reproduced, so I can investigate it further for you.
Looking forward for your reply.
Hi ,
It's hard to do it in my case but i will try to explain:
First of all my XamGrid sits in a DataTemplate (Content Presenter using ContentTemplateSelector).
I tried to add rowAdding and rowAdded events but it never enters them.
Secondly ,
My XamGrid itemssource is an observableCollection of object . Also this collection need to implement IEditableCollectionVIew.
Once AddNew is called , it returns new object. I must do it since i can't use default constructor to each object of the collection but i need to pass another object (The parentViewModel of the collection since each object in collection , which represents a row in the XamGrid has an indexer where i set/get the value to the cell of a specified column and create/edit the right object- this object has collection of another objects with represents the cell value).
The thing is that i can't understand the flow of addingRow.
When CanAddNEw and IsAddingNew is called and what i need to set there . Also what and when CommitNew is called since currently it never called.
with my previous code, it added first row correctly , but when it tried to add the second row, it adds it not throught the AddNew method but adds it automatically and returns an object with default constuctor applied (which gives me an error since i need to use the object i create in CTOR in Indexer)
But with my new code (can see below) it can't even add the first row since it is also created using default constructor (which gives me an error since i need to use the object i create in CTOR in Indexer):
public object AddNew() { CurrentAddItem = new FilterSetDefinitionAttributeRowViewModel(new FilterSetDefinitionAttributeRow()) {ParentViewModel = _parent}; return CurrentAddItem; } public void CommitNew() { Add((FilterSetDefinitionAttributeRowViewModel)CurrentAddItem); }
private NewItemPlaceholderPosition _newItemPlaceholderPosition; public NewItemPlaceholderPosition NewItemPlaceholderPosition { get { return NewItemPlaceholderPosition.AtBeginning; } set { _newItemPlaceholderPosition = value; } } public bool CanAddNew { get; set; } public bool IsAddingNew { get; set; } public object CurrentAddItem { get; set; } What am i missing?
private NewItemPlaceholderPosition _newItemPlaceholderPosition; public NewItemPlaceholderPosition NewItemPlaceholderPosition { get { return NewItemPlaceholderPosition.AtBeginning; } set { _newItemPlaceholderPosition = value; } } public bool CanAddNew { get; set; } public bool IsAddingNew { get; set; } public object CurrentAddItem { get; set; }
What am i missing?
I am still not completely sure that I understand your scenario correctly, but I suggest you see this forum thread:
http://stackoverflow.com/questions/2680759/wpf-ieditablecollectionview-and-canaddnew-and-empty-collections
and the sample from the MSDN about implementing IEditableCollectionView:
http://msdn.microsoft.com/en-us/library/cc716787(v=vs.90).aspx
Hope this helps you.
OK i will try to use it,
But still . First of all i never enters the RowAdding && RowAdded events of XamGrid.
Secondly,
What is the flow when XamGrid creates NewRow when IEditableCollectionView is not implemented?
When it calls AddNewRow, CanAddRow , IsAddingRow and CommitNewRow ?
You can use the XamGrid’s DataObjectRequested event, which fires when you add new row. Here you can read more about this event:
http://help.infragistics.com/NetAdvantage/Silverlight/2011.2/CLR4.0/?page=InfragisticsSL4.Controls.Grids.XamGrid.v11.2~Infragistics.Controls.Grids.XamGrid~DataObjectRequested_EV.html
Thanks.
It helped. works fine
Hello again,
Thank you for your feedback. I am glad that you resolved your issue and I believe that other community members may benefit from this as well.
Thanks again.