Oscar
Oscar

Reputation: 1147

How can I show data in a DataGrid in WPF?

I've got an enum and a Foo class:

public enum Type
{
    Arithmetic, Fraction, ...
}

public class Foo
{
    public Foo(Type problemType, bool isCorrect)
    {
        ProblemType = problemType;
        IsCorrect = isCorrect;
    }

    public Type ProblemType
    {
        get; set;
    }

    public bool IsCorrect
    {
        get; set;
    }
}

Then I have a Foo list, where it is classified by ProblemType:

    public void ShowGradesInDataGrid()
    {
        List<Foo> list = new List<Foo>();
        list.Add(new Foo(Type.Arithmetic, true));
        list.Add(new Foo(Type.Fraction, true));
        list.Add(new Foo(Type.Arithmetic, false));
        list.Add(new Foo(Type.Arithmetic, true));
        list.Add(new Foo(Type.Fraction, false));
        list.Add(new Foo(Type.Arithmetic, false));

        List<List<Foo>> groupedLists = list.GroupBy(foo => foo.ProblemType)
                                          .OrderBy(group => group.Key)
                                          .Select(group => group.ToList())
                                          .ToList();

    }

I don't know how to show the grupedLists in a datagrid in WPF. I was trying to show the list at this way:

Where I put Green and Red are rectangles with fill.

 if (IsCorrect)
     // put rectangle with fill green
 else
     // put rectangle with fill red

Well the color is a plus for me, I actually wnat to show the list classified in datagrid. Thanks in advance.

Upvotes: 0

Views: 137

Answers (1)

vrrathod
vrrathod

Reputation: 1240

I think what you are asking is something similar to this, Search for Grouping rows using ItemsControl.GroupStyle. As far as rectangles are concerned, you might want to use data triggers. check this out.
PS: both articles have data triggers in it, but the second one is better for understanding it.

Upvotes: 2

Related Questions