Ben
Ben

Reputation: 3912

Silverlight DataGridTemplate Column

I have a PropertyMapping Class that contains 2 properties - PropertyName and PropertyValue that I use to display objects in a SilverLight DataGrid.

Currently I just do a ToString() on each property value to force the grid to show something for each property. I have however know been asked to make the grid editable so that the values in the "PropertyValue" column are forced back onto the object.

In order to do this, I need to be able to display things like enumerations in the grid. I realise that you can have a templated column in the data grid, but this seems to set the template for every row in the column, can you set the individual cells template?

The reason being that I could be displaying an object that has a date property, and enumeration property and a string property - so the cell in the PropertyValue column for the Date row, would need to be a DateTimePicker, the cell for the enumeration cell would need to be a Combobox etc.

I have taken a look into iterating through all of the rows and setting the individual cells template, but can't find a way of doing this?

Is this possible? p.s I have the C1 DataGrid that I can use as well, if they have a way of doing this?

Upvotes: 2

Views: 613

Answers (1)

TerenceJackson
TerenceJackson

Reputation: 1786

have a look at the DataTemplate Selector for Silverlight. I guess, this is exactly what you need. A template for different data types. Here are some implementations:

http://csharperimage.jeremylikness.com/2010/11/silverlight-data-template-selector.html

http://geekswithblogs.net/tkokke/archive/2009/09/28/datatemplateselector-in-silverlight.aspx

Hope this helps you.

BR, TJ

Upvotes: 1

Related Questions