This question is locked. New answers and comments are not allowed.
Hi guys,
I have a radgridview that binds to a dynamic DataTable (telerik example datatable) and the columns are of a custom type defined here:
I have a radgridview that binds to a dynamic DataTable (telerik example datatable) and the columns are of a custom type defined here:
public
class
WorkDisplay
{
public
bool
? HomeworkDone {
get
;
set
; }
public
bool
? ClassworkDone {
get
;
set
; }
}
I need the cells in the column to display as two checkboxes per column. I have tried two approaches, first was creating the following xaml DataTemplate resource and then setting the CellTemplate in the autogenerating event:
<
DataTemplate
x:Key
=
"SimpleCheckBox"
>
<
StackPanel
Orientation
=
"Horizontal"
>
<
CheckBox
IsChecked
=
"{Binding Path=HomeworkDone}"
/>
<
CheckBox
IsChecked
=
"{Binding Path=ClassworkDone}"
/>
</
StackPanel
>
</
DataTemplate
>
private
void
radGridView1_AutoGeneratingColumn(
object
sender, Telerik.Windows.Controls.GridViewAutoGeneratingColumnEventArgs e)
{
if
(e.Column.Header.ToString() !=
"StudentName"
)
{
e.Column.CellTemplate = (DataTemplate)LayoutRoot.Resources[
"SimpleCheckBox"
];
}
}
The result of this was the checkboxes showing up in the grid, but neither of them checked/unchecked as per the data representation.
My second approach was doing my own custom column but ended with the same result. Here the code:
public
class
GridViewAssignmentsColumn : GridViewDataColumn
{
public
override
FrameworkElement CreateCellElement(GridViewCell cell,
object
dataItem)
{
var stackpanel = cell.Content
as
StackPanel;
if
(stackpanel ==
null
)
{
stackpanel =
new
StackPanel();
stackpanel.Orientation = Orientation.Horizontal;
CheckBox homeworkCheckBox =
new
CheckBox();
CheckBox classworkCheckBox =
new
CheckBox();
homeworkCheckBox.SetBinding(CheckBox.IsCheckedProperty,
new
Binding(
this
.DataMemberBinding.Path.Path.ToString())
{
// Source = dataItem,
Mode = BindingMode.OneWay,
Path =
new
PropertyPath(
"HomeworkDone"
)
});
classworkCheckBox.SetBinding(CheckBox.IsCheckedProperty,
new
Binding(
this
.DataMemberBinding.Path.Path.ToString())
{
// Source = dataItem,
Mode = BindingMode.OneWay,
Path =
new
PropertyPath(
"ClassworkDone"
)
});
stackpanel.Children.Add(homeworkCheckBox);
stackpanel.Children.Add(classworkCheckBox);
cell.Content = stackpanel;
}
return
stackpanel;
}
}
As you can see I've been reading through a number of the forums and blog postings :) but cannot come up with the precise code. I know I'm close but I'm stumped.