How can I set a View\edit DataGridview query to return results in ascending order

Hello

I would like to be able to amend the basic View\edit DataGridView query "mytable.Take(100)" command so that It will sort the data by date or newest ID and then allow me to edit whilst still in the DataGrid view

Can anybody help me?

Regards

Ian

Comments

  • Just use the normal Linq extensions and add the
    .OrderByDescending(x => x.ID)
    or whatever the ordering should be. You can also use .Where(...) to pre-filter your data etc.
  • Note: You have to add this before the .Take(100) method call, otherwise you get the first 100 entries and THEN order them (instead of ordering all entries and only take the top 100)

    You can also just remove the .Take call and use a .Where filter instead to display a more meaningful subset of your data
  • felixmohr

    Thank you, the ".OrderByDescending(x => x.ID)" solution worked perfectly.
  • felixmohr

    How could I amend the basic "mytable.Take(100)" command so I can request a specific record to be returned by ID number?

    Regards

    Ian
  • You can't edit the snippets on the context menu (although you can write Visual Studio style snippets that are accessible via shortcut text). It sounds like you want a snippet like myTable.First (x => x.ID == ....). Is that correct?
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!