Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I've try to load data to CollectionViewSource using below code.But it will throw exception.How can I solve this problem?

C#
_CollectionViewSource = (CollectionViewSource)this.FindResource("EmpAttendanceViewSource");
            if (dtp_Date.SelectedDate != null)
            {
                var obj = from ea in db.EmployeeAttendances
                          join emp in db.Employees
                          on ea.EmployeeId equals emp.EmployeeId
                          where ea.InDate == dtp_Date.SelectedDate
                          select new { emp.EmployeeFirstName, ea.InTime, ea.OutTime, ea.NoOfHours };
                _CollectionViewSource.Source = (CollectionViewSource)obj;


Exception Is,
{"A TwoWay or OneWayToSource binding cannot work on the read-only property 'InTime' of type '<>f__AnonymousType21`4[System.String,System.DateTime,System.Nullable`1[System.DateTime],System.Nullable`1[System.Double]]'."

Please help me.
Thanks,
Chamara
Posted

1 solution

It's hard to guess without WPF UI code, but you should be able to set the BindingMode to OneWay. In case 'InTime' property is set to TextBox

HTML
<textbox text="{Binding Path=InTime, Mode=OneWay}" />
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900