0

Hey im currently having problems with WPF Datagrid using linq, currently im displaying a group of records from three tables into a datagrid, this works fine and i retrieve all the relevant information correctly.

However when i load the datagrid and i click on for example the 3rd record it selects the first record and i cant change it. I can use Ctrl + click to deselect the first record.

I dont know why its doing this but ive narrowed it down to my linq query, ive tried to write a more complex linq query using joins etc, it retrieves the same data but i still have this problem :/ any ideas would be good...thank you in advance

apptGrid.ItemsSource = (from o in DbList.OrderedAppointmentList()
                                from s in DbList.StaffList()
                                from c in DbList.ClientList()
                                where o.Appointment_Date == apptDatePicker.SelectedDate.Value
                                && o.Staff_Staff_ID == s.Staff_ID && o.Client_Client_ID == c.Client_ID
                                select new
                                {
                                    o.Appointment_Date,
                                    o.Appointment_Time,
                                    o.Duration,
                                    StaffName =
                                        ((s.Middle_Name_s_ != null) ? s.First_Name + " " + s.Middle_Name_s_ + " " + s.Last_Name : s.First_Name + " " + s.Last_Name),
                                    ClientName =
                                   ((c.Middle_Name_s_ != null) ? c.First_Name + " " + c.Middle_Name_s_ + " " + c.Last_Name : c.First_Name + " " + c.Last_Name)
                                });
svick
  • 236,525
  • 50
  • 385
  • 514
Halfie44
  • 33
  • 1
  • 6

3 Answers3

1

I had something similar like you, but to me happen, that when i add rows with the same data information, the selection seems to be crazy. what i did was not give a linq query as a itemsource else put all the information into a List and next pass it to the item source.

Oscar
  • 11
  • 1
1

Try a ToList() at the end of the query.

svick
  • 236,525
  • 50
  • 385
  • 514
paparazzo
  • 44,497
  • 23
  • 105
  • 176
0

"ive tried to write a more complex linq query using joins etc,"

That's never going to help.

Write a program that is human readable (and not just computer readable). And I can bet, you will find the problem and the solution in that iteration.

Manish Basantani
  • 16,931
  • 22
  • 71
  • 103
  • Can you please explain? i say i done one with a more complex linq to see if it was the way i was getting the data, but its not, i think i may be overwriting soemthing – Halfie44 Feb 27 '12 at 17:39