I'm trying to change the text for the new row using the NewRowStyle, but my button does nothing:
<telerik:RadGridView ItemsSource="{Binding Data}" ShowInsertRow="True" x:Name="grd1" >
<telerik:RadGridView.NewRowStyle>
<Style TargetType="telerik:GridViewNewRow">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<telerik:RadButton Content="hello" Command="telerik:RadGridViewCommands.BeginInsert"
CommandTarget="{Binding ElementName=grd1}"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</telerik:RadGridView.NewRowStyle>
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn DataMemberBinding="{Binding A}" />
<telerik:GridViewDataColumn DataMemberBinding="{Binding B}" />
</telerik:RadGridView.Columns>
</telerik:RadGridView>
I suppose its something trivial, but I can't see it. The grid is bound to an ObservableCollection and without the style rows can be added ok.
Thanks,
Scott
6 Answers, 1 is accepted
Since you have predefined the template in such way the behavior you get is the expected one.
Regarding the template structure of GridViewNewRow you expect to enter data, however you have a single button and the DataCellsPresenter, which is responsible for displaying GridViewCells is missing. In these situations it would be much more appropriate to predefine the default template of GridViewNewRow and remove the elements from there rather than to define it in such way:
<telerik:GridLineWidthToThicknessConverter x:Key="GridLineWidthToThicknessConverter"/> <telerik:BooleanToOpacityConverter x:Key="BooleanToOpacityConverter"/> <telerik:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/> <SolidColorBrush x:Key="ControlInnerBorder" Color="White"/> <LinearGradientBrush x:Key="GridView_NewRowBackground" EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FF888888"/> <GradientStop Color="White" Offset="0.33"/> <GradientStop Color="#FFD0D0D0" Offset="0.66"/> <GradientStop Color="White" Offset="1"/> </LinearGradientBrush> <telerik:Office_BlackTheme x:Key="Theme"/> <SolidColorBrush x:Key="ControlOuterBorder" Color="#FF848484"/> <SolidColorBrush x:Key="GridView_GridLinesItemBorder" Color="#FFCBCBCB"/> <ControlTemplate x:Key="GridViewNewRowTemplate" TargetType="telerik:GridViewNewRow"> <telerik:SelectiveScrollingGrid x:Name="grid"> <telerik:SelectiveScrollingGrid.ColumnDefinitions> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="*"/> </telerik:SelectiveScrollingGrid.ColumnDefinitions> <telerik:SelectiveScrollingGrid.RowDefinitions> <RowDefinition Height="*"/> <RowDefinition Height="Auto"/> </telerik:SelectiveScrollingGrid.RowDefinitions> <VisualStateManager.VisualStateGroups> <VisualStateGroup x:Name="FocusStates"> <VisualState x:Name="Unfocused"/> <VisualState x:Name="Focused"/> </VisualStateGroup> <VisualStateGroup x:Name="SelectionStates"> <VisualState x:Name="Unselected"/> </VisualStateGroup> <VisualStateGroup x:Name="CommonStates"> <VisualState x:Name="Normal"/> <VisualState x:Name="MouseOver"/> <VisualState x:Name="Selected"/> </VisualStateGroup> <VisualStateGroup x:Name="ValueStates"> <VisualState x:Name="Valid"/> <VisualState x:Name="Invalid"> </VisualState> </VisualStateGroup> <VisualStateGroup x:Name="EditStates"> <VisualState x:Name="ReadOnlyMode"> <Storyboard> <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="PART_DataCellsPresenter"> <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Collapsed"/> </ObjectAnimationUsingKeyFrames> <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="PART_AlwaysVisibleNewRow"> <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Visible"/> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> <VisualState x:Name="EditMode"> <Storyboard> <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="PART_DataCellsPresenter"> <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Visible"/> </ObjectAnimationUsingKeyFrames> <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="PART_AlwaysVisibleNewRow"> <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Collapsed"/> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> </VisualStateGroup> </VisualStateManager.VisualStateGroups> <Border x:Name="PART_AlwaysVisibleNewRow" BorderBrush="{StaticResource ControlInnerBorder}" BorderThickness="1,1,1,2" Background="{StaticResource GridView_NewRowBackground}" Grid.ColumnSpan="4" Grid.Column="0" Margin="0" telerik:SelectiveScrollingGrid.SelectiveScrollingClip="True"> <Grid> <telerik:RadButton Click="RadButton_Click" telerik:LocalizationManager.ResourceKey="GridViewAlwaysVisibleNewRow" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> </Grid> </Border> <telerik:DataCellsPresenter x:Name="PART_DataCellsPresenter" Grid.Column="3" telerik:SelectiveScrollingGrid.SelectiveScrollingClip="True" telerik:StyleManager.Theme="{StaticResource Theme}" Visibility="Collapsed"/> </telerik:SelectiveScrollingGrid> </ControlTemplate> <SolidColorBrush x:Key="ItemBackground" Color="White"/> <Style TargetType="telerik:GridViewNewRow"> <Setter Property="Template" Value="{StaticResource GridViewNewRowTemplate}"/> <Setter Property="Background" Value="{StaticResource ItemBackground}"/> <Setter Property="BorderBrush" Value="{StaticResource GridView_GridLinesItemBorder}"/> <Setter Property="MinHeight" Value="25"/> <Setter Property="FontWeight" Value="Normal"/> <Setter Property="VerticalContentAlignment" Value="Center"/> <Setter Property="HorizontalContentAlignment" Value="Left"/> <Setter Property="Padding" Value="5,0,3,0"/> </Style> private void RadButton_Click(object sender, RoutedEventArgs e) { this.grid1.BeginInsert(); }Fell free to change it in the way you need.
Regards,
Vanya Pavlova
the Telerik team
Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>
--
Scott
If you need to modify only the default text "Click here to add new item" (not the appearance of GridViewNewRow) you may create your own CustomLocalizationManager and predefine the text for that particular key:
public class CustomLocalizationManager : LocalizationManager { public override string GetStringOverride(string key) { switch (key) { case "GridViewAlwaysVisibleNewRow": return "MyCustomText"; } return base.GetStringOverride(key); } }Then just set this LocalizationManager within the MainPage's constructor:
public MainPage() { InitializeComponent(); LocalizationManager.Manager = new CustomLocalizationManager(); }The other approach is to directly predefine the template of GridViewNewRow as it was proposed in my previous post.
All the best,
Vanya Pavlova
the Telerik team
Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>
I had seen that solution elsewhere, but unfortunately it suffers from not being able to change the text on a grid by grid basis. I will lodge a feature request.
The behavior occured because you have removed the default indicator of GridViewNewRow.
If you sent me a snapshot of the desired final result I will prepare an example for you which demonstrates how to achieve it using the xaml approach.
I look forward to hearing from you!
Vanya Pavlova
the Telerik team
Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>