This is a migrated thread and some comments may be shown as answers.

How Dynamical gridview for radButton in GridViewDataColumn

7 Answers 149 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Lior
Top achievements
Rank 1
Lior asked on 26 Sep 2012, 10:28 AM
Hi All,
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

Sort by
0
Vlad
Telerik team
answered on 26 Sep 2012, 10:40 AM
Hello,

 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.

0
Lior
Top achievements
Rank 1
answered on 26 Sep 2012, 11:06 AM
Hi, 
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.

0
Lior
Top achievements
Rank 1
answered on 26 Sep 2012, 11:07 AM
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;
0
Vlad
Telerik team
answered on 26 Sep 2012, 12:20 PM
Hi,

 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

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.

0
Lior
Top achievements
Rank 1
answered on 27 Sep 2012, 01:54 AM
Dear Vlad,
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.
0
Vlad
Telerik team
answered on 27 Sep 2012, 05:28 AM
Hi,

 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.

0
Lior
Top achievements
Rank 1
answered on 27 Sep 2012, 09:19 AM
Dear vlad,
We've resolve this scenario, return StackPanel and add childElements to it, and then return it.
Thank you for your quick response.
Tags
GridView
Asked by
Lior
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Lior
Top achievements
Rank 1
Share this question
or