tags:

views:

1388

answers:

3

Hi,

Is it possible to set DataGridCell's template when using WpfToolkit's DataGrid? Or is it possible to set style property for a single cell at the time?

I know that there is a TemplateColumn class which lets the user set templates for displaying and editing cell's data but that's not what I'm looking for.

I need to display two-dimensional arrays with DataGrid and style single cells according to their values. I'd also like to use VM-M-V model and create ViewModel wrapper for each cell which would have an IsSelected property binded to cell's IsSelected property so I could easily iterate over my data source for selected cell's instead of using DataGrid's more row oriented API.

A: 

Hi - did you ever find an answer to your question? I'd be interested to know of your solution, if any. Thanks!

A: 

I'd also be interested if you found and answer as I'm trying to have a datagrid where the colours are based on the date held in a datetime column.

+1  A: 

Here's a couple of ways I found to get started:

http://stackoverflow.com/questions/276808/how-to-populate-a-wpf-grid-based-on-a-2-dimensional-array

Another option is the following:

<List<string>> tempList = new List<List<string>> {
    new List<string> { "vince", "elizabeth", "brian", "mark" },
    new List<string> { "vince2", "elizabeth2", "brian2", "mark2" },
    new List<string> { "vince3", "elizabeth3", "brian3", "mark3" },
    new List<string> { "vince4", "elizabeth3", "brian3", "mark4" },
};

for(int i=0; i<tempList[0].Count; i++) {
    DataGrid_Standard.Columns.Add(new DataGridTextColumn {
            Header = i,
            DataFieldBinding = new Binding("[" + i + "]")
        });
}
DataGrid_Standard.ItemsSource = tempList;