We face an issue that we need to change current telerik grid to dynamical table(which is inherit from RadGridView,
In previous implementation, There is radButton in <telerik:GridViewDataColumn.CellTemplate>
Here is the sample code:
<telerik:GridViewDataColumn.CellTemplate>
<DataTemplate>
<telerik:RadButton Style="{StaticResource EditButtonStyle}" x:Name="EditButton" Margin="5,0,0,0" Command="{Binding EditCustomCommand, Source={StaticResource ViewModel}}" CommandParameter="{Binding}" / >
</DataTemplate>
</telerik:GridViewDataColumn.CellTemplate>
But in dynamic table, How should we add this button,in current dynamic table only has databinding property,
all column and row was created step by step for it.
How should we create these buttons by xml:
Here is my test code but no working:
case "RadButton":
GridViewDataColumn radButton = new GridViewDataColumn();
StringBuilder cellBuilder = new StringBuilder();
cellBuilder.Append("<DataTemplate ");
cellBuilder.Append("xmlns='http://schemas.microsoft.com/winfx/");
cellBuilder.Append("2006/xaml/presentation' ");
cellBuilder.Append("xmlns:telerik='http://schemas.telerik.com/2008/xaml/presentation' ");
cellBuilder.Append("xmlns:local='clr-namespace:BindableDataGrid;assembly=BindableDataGrid'> ");
cellBuilder.Append(" <telerik:RadButton Style='{StaticResource EditButtonStyle}' x:Name='EditButton' Margin='5,0,0,0' Command='{Binding EditCustomCommand, Source={StaticResource ViewModel}}' CommandParameter='{Binding}' ></telerik> ");
cellBuilder.Append("</DataTemplate>");
radButton.CellTemplate = (DataTemplate)XamlReader.Load(cellBuilder.ToString());
radButton.CellEditTemplate = (DataTemplate)XamlReader.Load(cellBuilder.ToString());
dgc = radButton;
Any suggestion ?
7 Answers, 1 is accepted
It will be better if you create custom column inherited from GridViewDataColumn (or GridViewColumn), override CreateCellElement and return desired UI element.
Greetings,Vlad
the Telerik team
Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.
Build Successfully and JIT was pass from these cs code :
GridViewDataColumn radButton = new GridViewDataColumn();
StringBuilder cellBuilder = new StringBuilder();
cellBuilder.Append("<DataTemplate ");
cellBuilder.Append("xmlns='http://schemas.microsoft.com/winfx/");
cellBuilder.Append("2006/xaml/presentation' ");
cellBuilder.Append("xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' ");
cellBuilder.Append("xmlns:telerik='http://schemas.telerik.com/2008/xaml/presentation' ");
cellBuilder.Append("xmlns:local='clr-namespace:BindableDataGrid;assembly=BindableDataGrid'> ");
cellBuilder.Append(" <telerik:RadButton Margin='5,0,0,0' />");
cellBuilder.Append("</DataTemplate>");
radButton.CellTemplate = (DataTemplate)XamlReader.Load(cellBuilder.ToString());
radButton.CellEditTemplate = (DataTemplate)XamlReader.Load(cellBuilder.ToString());
dgc = radButton;
We notice that the column was added to dynamictable, but the page was in blank and no response anymore.It seems it doesn't work.if we
inherited from GridViewDataColumn (or GridViewColumn) and create the radbutton, do you have any demo or sample code for reference, thank you in advance.
GridViewDataColumn radButton =
new
GridViewDataColumn();
StringBuilder cellBuilder =
new
StringBuilder();
cellBuilder.Append(
"<DataTemplate "
);
cellBuilder.Append(
"xmlns='http://schemas.microsoft.com/winfx/"
);
cellBuilder.Append(
"2006/xaml/presentation' "
);
cellBuilder.Append(
"xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' "
);
cellBuilder.Append(
"xmlns:telerik='http://schemas.telerik.com/2008/xaml/presentation' "
);
cellBuilder.Append(
"xmlns:local='clr-namespace:BindableDataGrid;assembly=BindableDataGrid'> "
);
cellBuilder.Append(
" <telerik:RadButton Margin='5,0,0,0' />"
);
cellBuilder.Append(
"</DataTemplate>"
);
radButton.CellTemplate = (DataTemplate)XamlReader.Load(cellBuilder.ToString());
radButton.CellEditTemplate = (DataTemplate)XamlReader.Load(cellBuilder.ToString());
dgc = radButton;
You can check these demos for more info about custom columns:
http://demos.telerik.com/silverlight/#GridView/RowNumber
http://demos.telerik.com/silverlight/#GridView/CustomColumn
Vlad
the Telerik team
Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.
I have a question about CreateCellElement method, this is create a single control in a cell,How about mutiple control in a cell. In current implementation, there r 2 radbuttons in a stackpanel by xaml
<
telerik:GridViewDataColumn.CellTemplate
>
<
DataTemplate
>
<
StackPanel
Style
=
"{StaticResource CenterControlsCombinationStackPanelStyle}"
>
<
telerik:RadButton
Style
=
"{StaticResource EditButtonStyle}"
x:Name
=
"EditButton"
Margin
=
"5,0,0,0"
Command
=
"{Binding EditCustomCommand, Source={StaticResource ViewModel}}"
CommandParameter
=
"{Binding}"
/>
<
telerik:RadButton
Style
=
"{StaticResource SimpleRemoveButtonStyle}"
x:Name
=
"RemoveButton"
Command
=
"{Binding RemoveCustomCommand, Source={StaticResource ViewModel}}"
CommandParameter
=
"{Binding}"
Margin
=
"5,0,5,0"
/>
</
StackPanel
>
</
DataTemplate
>
</
telerik:GridViewDataColumn.CellTemplate
>
For UI, pls refer 2 shot1.jpg.
If we inherit GridViewDataColumn class and override CreateCellElement , Does it support return a stackpanel with two radbuttons in it by override CreateCellElement method. If true, How do you do? if not, do you have any suggestions? Thank you in advance.
Yes. You can create and return as many controls as you need.
Greetings,Vlad
the Telerik team
Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.
We've resolve this scenario, return StackPanel and add childElements to it, and then return it.
Thank you for your quick response.