none
wpf + ef + datagrid + sorting = beurk... RRS feed

  • Question

  • i have :

    1 form with controls to edit a record (myrecord)

    1 grid on this form to edit sub details records (myrecord.details)

    it seems very very complicated to sort the datagrid according one column ???

    yes, i have been searching the forum and googling around, but it seems you need to write at least 10 lines of code just to do this, and you have to use subcollections that i never heard of...

    seems that EF is still is way to complicated... it helps you save 50 lines of code to link one table to a class (object) but then you loose plenty of time in all forms all around your software... doesn't look like a progress... brr...


    Steve
    Sunday, August 21, 2011 7:34 AM

Answers

  • Hi,

    Have you tried to use an ObservableCollection ? I gave it a try using the Northwind  sample database and

       NorthwindEntities db=new NorthwindEntities();
          dg.ItemsSource = new ObservableCollection<Categories>(db.Categories);
    

    is enough to sort on the id, name or description when I click the column.

    Perhaps could you point us on one of the article you saw so that we can better understand the context in which the code you are talking about is needed.


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".
    Sunday, August 21, 2011 1:29 PM
  • Hi Steve,

    Welcome!

    @Patrice is right!

    I think you can refer this link: Code First Model with Master-Detail WPF Application

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, August 22, 2011 3:26 AM
    Moderator
  • I ended up encapsulating all this in a :

    ObservableCollection, ListCollectionView, pretty much a lot of code for not something special... seems to work now. but it just refrain me to use more ef+wpf...

    thanks anyway for the tips


    Steve
    Sunday, August 28, 2011 10:03 AM

All replies

  • Hi,

    Have you tried to use an ObservableCollection ? I gave it a try using the Northwind  sample database and

       NorthwindEntities db=new NorthwindEntities();
          dg.ItemsSource = new ObservableCollection<Categories>(db.Categories);
    

    is enough to sort on the id, name or description when I click the column.

    Perhaps could you point us on one of the article you saw so that we can better understand the context in which the code you are talking about is needed.


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".
    Sunday, August 21, 2011 1:29 PM
  • Hi Steve,

    Welcome!

    @Patrice is right!

    I think you can refer this link: Code First Model with Master-Detail WPF Application

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, August 22, 2011 3:26 AM
    Moderator
  • Hi, 

    I am writing to check the status of the issue on your side.  Would you mind letting us know the result of the suggestions?

    If you need further assistance, please feel free to let me know.   I will be more than happy to be of assistance.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, August 26, 2011 3:22 AM
    Moderator
  • and can you edit the items in the grid as well ?

     

    thanks for your post

    Steve


    Steve
    Sunday, August 28, 2011 9:58 AM
  • I ended up encapsulating all this in a :

    ObservableCollection, ListCollectionView, pretty much a lot of code for not something special... seems to work now. but it just refrain me to use more ef+wpf...

    thanks anyway for the tips


    Steve
    Sunday, August 28, 2011 10:03 AM