I have used the following code to associate a table value to a button. I would like to do a similar thing to with a textbox, but I keep getting a NullReferenceException.
<Telerik:GridViewCell Foreground="#FFFFFFFF" Width="80" ColumnName="submittal" TextBlock.FontSize="16" Margin="770,0,0,0" HorizontalAlignment="Left">
<Telerik:GridViewCell.Template>
<ControlTemplate>
<Button Click="Button_Click" Background="Transparent" Foreground="White" ClickMode="Press" Tag="{Binding Path=Content, RelativeSource={RelativeSource TemplatedParent}}" AllowDrop="True" >
<TextBlock Width="75" Text="Submittal" />
</Button>
</ControlTemplate>
</Telerik:GridViewCell.Template>
</Telerik:GridViewCell>
What is wrong with:
<
Telerik:GridViewCell Foreground="#FFFFFFFF" Width="80" ColumnName="submittal" TextBlock.FontSize="16" Margin="770,0,0,0" HorizontalAlignment="Left">
<Telerik:GridViewCell.Template>
<ControlTemplate>
<TextBox Text="{Binding Path=Content, RelativeSource={RelativeSource TemplatedParent}}" AllowDrop="True" >
</TextBox>
</ControlTemplate>
</Telerik:GridViewCell.Template>
</Telerik:GridViewCell>
?
8 Answers, 1 is accepted
Looking at the XAML you posted, I am wondering how you access that GridViewCell object. In order for it to work properly, the cell must be contained in a GridViewRow object. Can you post your entire RadGridView template setting?
As far as cell templating goes, probably the easiest way to approach this is to define a style targeting the GridViewCell controls inside the grid. Using your settings, it should look like:
<Style TargetType="{x:Type telerik:GridViewCell}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Button Click="Button_Click"
Background="Transparent" Foreground="White" ClickMode="Press"
Tag="{Binding Path=Content, RelativeSource={RelativeSource TemplatedParent}}" AllowDrop="True" >
<TextBlock Width="75" Text="Submittal" />
</Button>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
This way, all your cells will contain a button that will have its Click event hooked to the Button_Click method. I am attaching a sample project that handles that and puts up a message box with the Button.Tag value.
Sincerely yours,
Hristo Deshev
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center

I have had a look at your example, because i had some of the same isue but with a text box instead of a button. When I change the Theme on your example and also in my own project the controls is not in the grid anymore i add below to the RadGridView tag
telerik:Theming.Theme = "Simple"
but then all Controls is gone from the grid. Its like when changing the Theme all controltemplates is being overridden. why is that and how can i change the theme and also keep my controltemplates.
Martin L
We recently discovered that issue as well. It is caused by a bug in the logic that applies the theme. We have resolved it, and templates will not get overriden by theme styles anymore.
The fix will make it in Beta 2 (scheduled for Monday).
All the best,
Hristo Deshev
the Telerik WPF team
Instantly find answers to your questions at the new Telerik Support Center

The following is the XAML for the window. I believe that I am doing the same thing you proposed except that I have defined the controltemplate and then linked it to the style.
<Window xmlns:my4="clr-namespace:System.Windows.Controls;assembly=PresentationFramework" xmlns:my3="clr-namespace:System.Windows.Controls;assembly=PresentationFramework" xmlns:my2="clr-namespace:System.Windows.Controls;assembly=PresentationFramework" xmlns:my1="clr-namespace:System.Windows.Controls;assembly=PresentationFramework"
xmlns:my="clr-namespace:System.Windows.Controls;assembly=PresentationFramework"
xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation
xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
xmlns:Telerik="clr-namespace:Telerik.Windows.Controls.UI;assembly=Telerik.Windows.Controls.UI" x:Class="Window1"
x:Name="Window1" HorizontalAlignment="Left" xmlns:d=http://schemas.microsoft.com/expression/blend/2008
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" Background="{DynamicResource Brush1}" AllowsTransparency="False"Height="500" Width="1000">
<Window.Resources>
<ControlTemplate x:Key="MyCustomRowTemplate" TargetType="{x:Type Telerik:GridViewRow}">
<Border Background="Transparent" x:Name="selectedRow" Margin="0" Opacity="1" BorderThickness="0,1,0,1" VerticalAlignment="Top" BorderBrush="#0000BBFF" HorizontalAlignment="Left">
<Grid MinWidth="600" Focusable="True" HorizontalAlignment="Left">
<Grid.Resources>
</Grid.Resources>
<Border Height="Auto" HorizontalAlignment="Left" Background="#FF233052" Margin="2,1,0,0" BorderBrush="#FFFFFFFF" CornerRadius="5,5,5,5" orderThickness="1" />
<Border Height="Auto" Grid.Row="1" HorizontalAlignment="Left" Background="#FF5E78BA" Margin="20,1,0,0" Width="1000" BorderBrush="#FFFFFFFF" CornerRadius="5,5,5,5" BorderThickness="1" />
<Telerik:GridViewCell Foreground="#FFFFFFFF" Width="200" Margin="20,0,0,0" HorizontalAlignment="Left" ColumnName="catalogno" TextBlock.FontSize="16" />
<Telerik:GridViewCell TextBlock.Foreground="#FFFFFFFF" ColumnName="description" Width="550" Margin="220,0,0,0" HorizontalAlignment="Left">
<Telerik:GridViewCell.Template>
<ControlTemplate>
<TextBlock TextWrapping="Wrap" Width="550" Text="{Binding Path=Content, RelativeSource={RelativeSource TemplatedParent}}"/>
</ControlTemplate>
</Telerik:GridViewCell.Template>
</Telerik:GridViewCell>
<Telerik:GridViewCell Foreground="#FFFFFFFF" Width="80" ColumnName="submittal" TextBlock.FontSize="16" Margin="770,0,0,0" HorizontalAlignment="Left">
<Telerik:GridViewCell.Template>
<ControlTemplate>
<Button Click="Button_Click" Background="Transparent" Foreground="White" ClickMode="Press" Tag="{Binding Path=Content, RelativeSource={RelativeSource TemplatedParent}}" AllowDrop="True" >
<TextBlock Width="75" Text="Submittal" />
</Button>
</ControlTemplate>
</Telerik:GridViewCell.Template>
</Telerik:GridViewCell>
<Telerik:GridViewCell Foreground="#FFFFFFFF" Width="80" ColumnName="Instructions" TextBlock.FontSize="16" Margin="850,0,0,0" HorizontalAlignment="Left">
<Telerik:GridViewCell.Template>
<ControlTemplate>
<Button Click="Button_Click" Background="Transparent" Foreground="White" ClickMode="Press" Tag="{Binding Path=Content, RelativeSource={RelativeSource TemplatedParent}}" AllowDrop="True" >
<TextBlock Width="75" Text="Instruction" />
</Button>
</ControlTemplate>
</Telerik:GridViewCell.Template>
</Telerik:GridViewCell>
<Telerik:GridViewCell Foreground="#FFFFFFFF" Width="2" Margin="0,5,0,0" HorizontalAlignment="Left" ColumnName="prodclassdesc" TextBlock.FontSize="16" Visibility="Collapsed" VerticalAlignment="Center"/>
<Telerik:GridViewCell Foreground="#FFFFFFFF" Width="80" Margin="930,0,0,0" HorizontalAlignment="Left" ColumnName="quantity" TextBlock.FontSize="16" >
</Telerik:GridViewCell>
</Grid>
</Border>
</ControlTemplate>
<Style TargetType="{x:Type Telerik:GridViewRow}">
<Setter Property="Template" Value="{StaticResource MyCustomRowTemplate}"/>
</Style>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="23"/>
<RowDefinition Height="23"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid MinWidth="500" MinHeight="500" Grid.Row="2">
<my:RadGridView Name="RadGridView1" xmlns:my="clr-namespace:Telerik.Windows.Controls.UI;assembly=Telerik.Windows.Controls.UI" HorizontalAlignment="Left" VerticalAlignment="Top" AutoGenerateColumns="False" ColumnsWidthMode="None" VerticalGridLinesVisibility="Collapsed">
<Telerik:RadGridView.Columns>
<Telerik:GridViewDataColumn DataType="{x:Null}" UniqueName="catalogno" />
<Telerik:GridViewDataColumn DataType="{x:Null}" UniqueName="description" />
<Telerik:GridViewDataColumn DataType="{x:Null}" UniqueName="submittal">
</Telerik:GridViewDataColumn>
<Telerik:GridViewDataColumn DataType="{x:Null}" UniqueName="instructions" />
<Telerik:GridViewDataColumn DataType="{x:Null}" UniqueName="prodclassdesc" HeaderText=""/>
<Telerik:GridViewDataColumn DataType="{x:Null}" UniqueName="quantity" IsReadOnly="False"/>
</Telerik:RadGridView.Columns>
</my:RadGridView>
</Grid>
<ComboBox Height="23" VerticalAlignment="Top" Name="CmbSeries" Width="100" HorizontalAlignment="Left" Grid.Row="0"/>
<Menu Grid.RowSpan="2" HorizontalAlignment="Left" Margin="131,12,0,12" Name="Menu1" Width="200" />
</Grid>
/Window>

As far as I can tell from the XAML code, you are placing a GridViewCell control on your window, outside the RadGridView and a corresponding GridViewRow control. That scenario is not supported as a GridViewCell control cannot do much just by itself.
The best way to customize your grid cells is to use just a RadGridView control and add a style targeting the GridViewCell controls inside as I did in my example.
Kind regards,
Hristo Deshev
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center

<Style TargetType="{x:Type Telerik:GridViewRow}">
<Setter Property="Template" Value="{StaticResource MyCustomRowTemplate}"/>
</Style>
which takes what is in the controltemplate MyCustomRowTemplate and applies the style to the Telerik:GridViewRow. Which is how I am able to do the button thing to the gridview row items submittal and instructions. Buttons are working fine. The issue is I cannot get the same sort of thing to work for a textbox instead of a button. I could not find any part of your examples that deal with a textbox in a gridview. Buttons are great in grids, but being able to edit some text in a row without having to first go into edit mode is real handy. Can you please supply the Xaml for a textbox gridviewcell that will work rather than the button example?
I managed to get your original XAML running and reproduced the NullReferenceException. Our code makes an unfounded assumption about having a certain type of control in the template and, of course, breaks when that template is heavily modified. Luckily, we managed to fix the problem for the second beta (to be released tomorrow).
In the meantime, I have been thinking on how to create a cell that would contain both a textbox and a button. I managed to create an effect similar to the one you are after by using a stack panel. Here is my style:
<Grid.Resources>
<Style TargetType="{x:Type telerik:GridViewCell}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<StackPanel Orientation="Horizontal">
<TextBox Text="{Binding Path=Content, RelativeSource={RelativeSource TemplatedParent}}"></TextBox>
<Button Click="Button_Click"
Background="Transparent" Foreground="White" ClickMode="Press"
Tag="{Binding Path=Content, RelativeSource={RelativeSource TemplatedParent}}" AllowDrop="True" >
<TextBlock Width="75" Text="Submittal" />
</Button>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Grid.Resources>
You can try using that approach or just wait till tomorrow and use the Beta 2 build.
Kind regards,
Hristo Deshev
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center