3

I would like to sort a datagridview with multiple actions.

I explain myself: I've a dictionnary with a key and a value. The value is a string with ASC or DESC and I'd like to sort everything with this strategy:

string sort=String.Empty;
sort+=".OrderBy(c=>c.Value)"; ==> the first one in my list
foreach(var column in list) 
{
    if(column.Value=="DESC")
        sort+=".ThenByDescending(c=>c.Value)";

    if(column.Value=="ASC")
        sort+=".ThenByAscending(c=>c.Value)";
}

List<Formule> list=ListFormules.Where(f=>f.Identificator==null)==> It's my problem

I don't know how to change my string to work in my query. Have you an idea or a better way to do that?

3
  • 2
    Check out dynamic linq. link Commented Apr 15, 2013 at 12:06
  • 1
    +1 @scheien - should probably be expanded to a full answer..! Commented Apr 15, 2013 at 12:11
  • @AlexG It is impossible to even count all the answers where this was already explained... Commented Apr 15, 2013 at 12:13

1 Answer 1

2

Post my comment as an answer due to comments.

You should check out dynamic linq.

Scott Guthrie has a detailed blog post about it. Link

Sign up to request clarification or add additional context in comments.

1 Comment

You may want to expand your answer somewhat, however, as link-only-answers are considered largely unhelpful due to possible link-rot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.