Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
805
RequireEmptyConstructorException
posted

Hello,

I have a grid with a couple of manually created fields of Type TextColumn. I've set AutoGenerateColums to false.

Now I'm trying to bind ( with ItemSource)  the grid with a collection of my data of Type ObservableCollection<string[]>.

I'm always getting the RequireEmptyConstrucor Exception: The DataManager attempted to create an instance of a class which does not have an empty parameter list.

I really hope someone can help me with this issue. Thanks.

Enrico

  • 21382
    Verified Answer
    posted

    The XamWebGrid will attempt to make a new data object of your bound object for situations like Filtering and AddNewRow.  When it does it looks to use the empty input constructor of the object.   If it cannot find one, it raises an exception in order to notify you that it needs this data object created for it.

     

    Arrays don't usually have empty constructors, they either require a default list or require you declare its size.

     

    Handle the XamWebGrid's DataObjectRequested event.  In there, check to see what object is currently being made, and then if it is the object type that needs developer action provide an object of the correct type.

     

    private void dataGrid_DataObjectRequested(object sender, DataObjectCreationEventArgs e)

    {

    if (e.ObjectType== typeof(string[]))

    {

    e.NewObject= new string[5];

    }

     

  • 110
    posted

    Hi, 

    I'm facing the same issue and can't able to resolve it.

    I'm assign ObservableCollection<Class1>(records) to xamgrid.itemsource.

    Class1 constructor contains 3 more classes IEnumerable<class2/3/4> in parameter and last argument is string [].

    Class2/3/4 has empty constructor but string[] don't. I need to use string[] or list<string> as last parameter.

    How can I achieve this or resolve this issue.

    Please Help !!!

    Thanks