Hello,
We are using 2012 Q3
I am AutoGenerating columns from a datatable to populate a RadGridView.
In the table there are columns who's DataType is a tuple with a couple strings, defined as "characteristic columns".
I tried setting the cell template using the following code,
private void OneStopGrid_DataLoaded(object sender, EventArgs e)
{
foreach (GridViewColumn column in OneStopGrid.Columns)
{
if (ViewModel.CharacteristicColumns.Any(c => c.Name == column.Header))
{
column.CellTemplate = (DataTemplate)this.FindResource("HistoryTemplate");
}
}
}
The history template is a stackpanel containing a textblock which basically binds to one of the strings using Text="{Binding Item1}", and a rectangle which is standing in for a button.
The cell template is correctly set, but the datacontext is wrong, when I set the binding to Text="{Binding}" it showed that in the cells the datacontext was the DataRow.
I looked on the forums and found
http://www.telerik.com/community/forums/wpf/gridview/programmatically-creating-templated-columns.aspx
which advised me to to go to
http://blogs.telerik.com/vladimirenchev/posts/10-05-13/how-to-custom-percentage-column-with-radgridview-radprogressbar-and-radslider-for-silverlight-and-wpf.aspx
I set up a custom column as recommended and overrode the CreateCellElement using the following code
Then I used the ColumnsGenerating event to set up the columns as my custom column
private void OneStopGrid_AutoGeneratingColumn(object sender, GridViewAutoGeneratingColumnEventArgs e)
{
if (ViewModel.CharacteristicColumns.Any(c => c.Name == e.Column.Header))
{
var templateColumn = new GridViewCharacteristicColumn();
templateColumn.Header = e.Column.Header;
e.Column = templateColumn;
}
}
Unfortunately I am still having the same problem. The Context is still the DataRow.
Anything I can do to get the binding to work correctly?
Thank you.
We are using 2012 Q3
I am AutoGenerating columns from a datatable to populate a RadGridView.
In the table there are columns who's DataType is a tuple with a couple strings, defined as "characteristic columns".
I tried setting the cell template using the following code,
private void OneStopGrid_DataLoaded(object sender, EventArgs e)
{
foreach (GridViewColumn column in OneStopGrid.Columns)
{
if (ViewModel.CharacteristicColumns.Any(c => c.Name == column.Header))
{
column.CellTemplate = (DataTemplate)this.FindResource("HistoryTemplate");
}
}
}
The history template is a stackpanel containing a textblock which basically binds to one of the strings using Text="{Binding Item1}", and a rectangle which is standing in for a button.
The cell template is correctly set, but the datacontext is wrong, when I set the binding to Text="{Binding}" it showed that in the cells the datacontext was the DataRow.
I looked on the forums and found
http://www.telerik.com/community/forums/wpf/gridview/programmatically-creating-templated-columns.aspx
which advised me to to go to
http://blogs.telerik.com/vladimirenchev/posts/10-05-13/how-to-custom-percentage-column-with-radgridview-radprogressbar-and-radslider-for-silverlight-and-wpf.aspx
I set up a custom column as recommended and overrode the CreateCellElement using the following code
Then I used the ColumnsGenerating event to set up the columns as my custom column
private void OneStopGrid_AutoGeneratingColumn(object sender, GridViewAutoGeneratingColumnEventArgs e)
{
if (ViewModel.CharacteristicColumns.Any(c => c.Name == e.Column.Header))
{
var templateColumn = new GridViewCharacteristicColumn();
templateColumn.Header = e.Column.Header;
e.Column = templateColumn;
}
}
Unfortunately I am still having the same problem. The Context is still the DataRow.
Anything I can do to get the binding to work correctly?
Thank you.