DataGrid problems

Mar 1, 2010 at 10:45 AM

Hello I have a problem:)First, I own two classes Customer and Purchase in class customer I have a IList <Compras>, the DataGrid can I show the first column the name of my client and the other columns are created by the IList <Compras>? I use Entity Framework.

Second, as I paint a specific cell of the DataGrid, for example painting the cell in row 5 column 3.


Thank you for your attention

Mar 1, 2010 at 1:54 PM


Top of the list when I googled on wpf entity framework binding was:

If you wanted more examples there were dozens of other links returned.


The second question seems incomplete.

The way you would do stuff with the rows in datagrid would not usually have anything to do with saying row 5 column 3.

Datatemplates, datatriggers and binding are more likely to be involved.

Mar 3, 2010 at 12:26 PM
Edited Mar 3, 2010 at 12:30 PM

Hello thanks for the reply.
We coneguimos solve the problem of data using a StoredProcedure that dynamically creates the columns and everything else, was not an easy job:)

Now I set the DataContext of my Grid as the DataSet with data from the Procedure, and ItemsSource Binding Tables = ([]) so far so good, it creates the grid without problems.


Because the dataset is the right way, I set AutoGeneratedColumns = True, but then I like to do an Upgrade to analyze cell by cell, like this:

Value = Free -> Background color green
Value = Busy -> Background color red

Is it possible?

Mar 3, 2010 at 7:26 PM
Edited Mar 3, 2010 at 7:26 PM

Dude, I'm not very used to WPF, but I had this issue once in WinForms. I solved it implementing an event called OnCellPaint. Try checking the events of you grid.

See ya!

Mar 3, 2010 at 7:33 PM

Hello Zóio.
Unfortunately, in WPF there is no such event, I can not even paint the cell after seeking the same, at least not found the way to do that:)

Mar 4, 2010 at 2:44 PM

You guys are thinking way too low of level when dealing with WPF. 

To change the color of a cell based on a value you can simply create a cell style with a datatrigger.

Maybe this example will give you some ideas.