Hello,
I have a RadGridView where I am autogenerating columns from a datatable. Some columns need a converter on the values, and the conversion logic is different from column to column.
I am using the following code in the autogenerating column event to set the template to an object with a textblock and the right converter.
var cellStyle = new Style();
Setter setter = new Setter();
setter.Property = TemplateProperty;
var template = new ControlTemplate();
var index = "[" + ((RadGridView)sender).Columns.Count.ToString() + "]";
FrameworkElementFactory spFactory = new FrameworkElementFactory(typeof(System.Windows.Controls.ListBox));
var value = new MultiBinding();
value.Bindings.Add(new Binding(index));
var columnBinding = new Binding();
columnBinding.Source = e.Column.Header.ToString();
value.Bindings.Add(columnBinding);
value.Converter = (IMultiValueConverter)this.FindResource("TupleCreator");
spFactory.SetValue(DataContextProperty, value);
spFactory.SetValue(TemplateProperty, (ControlTemplate)this.FindResource("DataTemplate"));
template.VisualTree = spFactory;
setter.Value = template;
cellStyle.Setters.Add(setter);
e.Column.CellStyle = cellStyle;
This works fine for actually viewing the cells in the grid, and using visualization so that not all of the conversions are done at once. What I need to be able to do is filter and sort by these values, as well as have them in the cells of export to excel.
I have seen something similar done in another control using an unbound column data event.
Thanks,
Eli
I have a RadGridView where I am autogenerating columns from a datatable. Some columns need a converter on the values, and the conversion logic is different from column to column.
I am using the following code in the autogenerating column event to set the template to an object with a textblock and the right converter.
var cellStyle = new Style();
Setter setter = new Setter();
setter.Property = TemplateProperty;
var template = new ControlTemplate();
var index = "[" + ((RadGridView)sender).Columns.Count.ToString() + "]";
FrameworkElementFactory spFactory = new FrameworkElementFactory(typeof(System.Windows.Controls.ListBox));
var value = new MultiBinding();
value.Bindings.Add(new Binding(index));
var columnBinding = new Binding();
columnBinding.Source = e.Column.Header.ToString();
value.Bindings.Add(columnBinding);
value.Converter = (IMultiValueConverter)this.FindResource("TupleCreator");
spFactory.SetValue(DataContextProperty, value);
spFactory.SetValue(TemplateProperty, (ControlTemplate)this.FindResource("DataTemplate"));
template.VisualTree = spFactory;
setter.Value = template;
cellStyle.Setters.Add(setter);
e.Column.CellStyle = cellStyle;
This works fine for actually viewing the cells in the grid, and using visualization so that not all of the conversions are done at once. What I need to be able to do is filter and sort by these values, as well as have them in the cells of export to excel.
I have seen something similar done in another control using an unbound column data event.
Thanks,
Eli