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
50
InitializeRecord Unbound Boolean field error
posted
I am trying to use the InitializeRecord event to init an Unbound boolean field to false.  However when I do this the expansion toggle on my records no longer work and I get the following error in the output window.  I attached a simple project showing the error - run it and try to expand one of the Categories.  If I remove the SetCellValue call (line 34), it works fine.  Am I doing something wrong when I set my boolean field, or is this a bug?

System.Windows.Data Error: 8 : Cannot save value from target back to source. BindingExpression:Path=IsExpanded; DataItem='DataRecordPresenter' (Name=''); target element is 'ExpansionIndicator' (Name='ExpansionIndicator'); target property is 'IsChecked' (type 'Nullable`1') TargetInvocationException:'System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: key not found

at Infragistics.Windows.DataPresenter.FieldCollection.get_Item(String key)

at InitializeRecordProblem.Window1.xamDataGrid1_InitializeRecord(Object sender, InitializeRecordEventArgs e) in D:\development\Stuff\Examples\InitializeRecordProblem\InitializeRecordProblem\Window1.xaml.cs:line 34
...

InitializeRecordProblem.zip
Parents
No Data
Reply
  • 2320
    Verified Answer
    posted

    It's because InitializeRecord is called on every single record in the datagrid - the child records as well as the parent records - and the child records don't have a field called "Selected". This is what's throwng the error. So you'll have to check whether you're trying to initialise the parent record or the child record before setting that field. 

     

    If you want the entire field to be false on startup, you don't even need to set it in code behind because the default value for a boolean field is already false. 

Children