I'm using the WPF DataGrid
from the WPF Toolkit.
I added a templated column to my DataGrid
, which has a CheckBox
in each cell. Now how do I access the values within these cells?
My other columns in the DataGrid
come from a DataSet
. I can access these, but I cannot get to the values of the DataGridTemplateColumn
I added to the DataGrid
.
Anyone have any ideas?
your into pulling stuff out of the visual tree now. and thats hard work, you cant find the binding because that is buried in the cell template. what i did was add my own column for this kind of stuff, the column derives from DataGridBoundColumn, which means it has a binding like all the others: ( i wrote it a while ago, it could probably do with some looking at ) This lets me just use a straight binding. i dont have to set a cell template, i can just use a DataTemplate which i like better.
now if you can get to the column you can get to the binding on the column. if you can get to the cell then you can find the data item (the row data). then what i do is follow the binding to get the cell value. it is really inefficient, and it is a hack. but it works. to follow the binding i use this.
and the last piece is a helper class called BindingEvaluator which has one dp, that i use to follow the binding
and i call it like so: