Quantcast
Channel: Extended WPF Toolkit™ Community Edition
Viewing all articles
Browse latest Browse all 4964

Commented Unassigned: CollectionControl.PersistChanges exception [20216]

$
0
0
Hi,

I have a nested structure of classes assigned to a PropertyGrid.
When i edit a collection field, the collection editor opens, fine.
Now when i change a (string) value in the collection editor and press the OK button an exception is thrown, from the code below.

The exception
2013-09-20 08:48:33,348 [9] FATAL Twister.App - CurrentDomain_UnhandledException - Unhandled exception : System.NotSupportedException: Collection was of a fixed size.
at System.Array.System.Collections.IList.Add(Object value)
at Xceed.Wpf.Toolkit.CollectionControl.PersistChanges()

The code where it is thrown
CollectionControl.c
public void PersistChanges()
{
IList list = ComputeItemsSource();
if( list == null )
return;

//the easiest way to persist changes to the source is to just clear the source list and then add all items to it.
list.Clear();

foreach( var item in Items )
{
list.Add( item ); <-------------------------- EXCEPTION
}
}

My data structure looks like this

// VectorType --- Data(list/collection of DataType)
// --- ID (string)

// DataType --- class(ExpectedKeywordSectionType)
// --- class(InputKeywordSectionType)
// --- Objective (string)

An VectorType instance is assigned to the SelectedObject of my PropertyGrid, and i'm trying to edit the Objective (in the collectioneditor)
In the debugger i saw that the 'list' object has property 'IsFixedSize = true', maybe a check should be added here?
But what is more important for me; how could i prevent this from happening? Is it my data structure that is not supported or is there a workaround for this?

Attached is a debugger screenshot with relevant values just before the point the exception is thrown.

Thanks in advance,

Ruud
Comments: ** Comment from web user: BoucherS **

Hi,

Here's a workaround.
You can add a check for an array type and fill the "list" array item by item.
In CollectionControl.PersistChanges(), just replace
```
foreach( var item in Items )
{
list.Add( item );
}
```
with
```
if( list.GetType().BaseType == typeof( System.Array ) )
{
for( int i = 0; i < Items.Count; ++i )
list[ i ] = Items[ i ];
}
else
{
foreach( var item in Items )
{
list.Add( item );
}
}
```
This problem will be fixed in v2.1.


Viewing all articles
Browse latest Browse all 4964

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>