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
1235
Weird error message when binding ItemsSource to IEnumerable<T> and solution
posted

 

Hello,
I ran into this  issue and I wanted to signal it if someone else stumble on it as well.

XAML
XAML
 <ig:XamGrid ItemsSource="{Binding Path=GridTreatmentDetails}" 
                            AutoGenerateColumns="False" >
  <ig:XamGrid.Columns>
      <ig:DateColumn Key="DetailDateAsDateTime" HeaderText="DATA"/>
      <ig:TextColumn Key="Description" HeaderText="DESCRIZIONE"/>
       <ig:TextColumn Key="LastAndFirstName" HeaderText="PAZIENTE"/>
       <ig:TextColumn Key="TranslatedState" HeaderText="STATO"/>
   </ig:XamGrid.Columns> 
 <ig:XamGrid ItemsSource="{Binding Path=GridTreatmentDetails}" 
                            AutoGenerateColumns="False" >
  <ig:XamGrid.Columns>
      <ig:DateColumn Key="DetailDateAsDateTime" HeaderText="DATA"/>
      <ig:TextColumn Key="Description" HeaderText="DESCRIZIONE"/>
       <ig:TextColumn Key="LastAndFirstName" HeaderText="PAZIENTE"/>
       <ig:TextColumn Key="TranslatedState" HeaderText="STATO"/>
   </ig:XamGrid.Columns> 

ViewModel
 GridTreatmentDetails = workHorseQuotes
.SelectMany(td => td.MergedTreatmentDetails);
GridTreatmentDetails is an IEnumerable<T> where T
is my custom class.
I receive a runtime error that says:
 The following key(s) do not correspond with the DataSource: "DetailDateAsDateTime".
If you'd like to add additional columns, please use the UnboundColumn type.
 The following key(s) do not correspond with the DataSource: "DetailDateAsDateTime".
If you'd like to add additional columns, please use the UnboundColumn type.
It looks like my class does not have a DateTime property named  DetailDateAsDateTime, but in fact 
I do have this property.
To solve the issue you need to modify:
 GridTreatmentDetails = workHorseQuotes.SelectMany(td => td.MergedTreatmentDetails);
as following: 
It looks like my class does not have a DateTime property named  DetailDateAsDateTime, but in fact
I do have this property.
To solve the issue you need to modify:
 GridTreatmentDetails = workHorseQuotes
.SelectMany(td => td.MergedTreatmentDetails);
as following:
GridTreatmentDetails = workHorseQuotes
.SelectMany(td => td.MergedTreatmentDetails).ToList();
Now, while I can understand the reason (now), it would help immensly to receive a different error message.
Best regards
Roberto 


 

Parents Reply Children
No Data