DataGrid visualizing not read state with templateselector

Mar 27, 2009 at 11:42 AM
Edited Mar 27, 2009 at 1:02 PM

In my application I am trying to visualize if the transaction shown in my DataGrid are read or unread by making them bold if they are unread. When a user clicks on a row the transaction gets marked as read and should no longer be visible.
I did this with the CellTemplateSelector. But I have to write different templates for each Column in my DataGrid, because the properties shown in the columns are very differnet. It's like 30 or more templates and Template Selectors I need and I think this is very much for this little thing.

I would like to know if there is a way, to set the whole row's fontweight to bold if the object in this row has the read-status set to false??

In the SelectionChanged-Event I am setting the read-property to true. But the Template is not changed. How do I tell the cells to reload the template when the read-property changes?

Thanks in advance!
Mar 27, 2009 at 9:46 PM
Setting the FontWeight on DataGridRow should work for you. The best way to do it is to have a property in your ViewModel which represents the Marked-ness of the row and bind the FontWeight of row to that property in RowStyle.
Mar 30, 2009 at 8:12 AM
Thank you!
This works realy fine for me.

But I have another small problem in this case.
When the user clicks on a row the read-status must be saved immediataly into the database, because it is the only time it is sure, that the read-status is the only change on the object. So I say in the selection-changed eventhandler. I can only save the whole ItemsSource of the datagrid, because the objects are childs and chields cannot be saved without their parent in our scenario. So the whole ItemsSource gets saved and the DataGrid is reloaded. A multiple selection is possible. When saving the read-status the selection gets lost.
Is there a way to somehow save the selected rows and when the grid reloads to select them again? Or any other suggestions handling the read-status save?

Thanks in advance!
Apr 1, 2009 at 9:33 AM
I googled for hours. But I found no answer on the question how to save which Items in the grid are checked and redo this checking after the itemssource gets reloaded.
It would be really great if anybody here could help me! Please!