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

Get RichTextBox in CellEditTemplate form the code behind

2 Answers 72 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Harald
Top achievements
Rank 2
Harald asked on 14 Jul 2019, 02:27 PM

How can I assign in the code behind a German Dictionary to a RichTextBox in the CellEditTemplate?

01.<telerik:GridViewDataColumn.CellEditTemplate>
02.  <DataTemplate>
03.    <Grid>
04.      <telerik:RadRichTextBox x:Name="ProtocolRowTextBox"
05.                              IsSpellCheckingEnabled="True"
06.                              BorderThickness="0" 
07.                              Height="Auto"
08.                              Margin="0"
09.                              DocumentInheritsDefaultStyleSettings="True"/>
10.      <telerik:TxtDataProvider RichTextBox="{Binding ElementName=ProtocolRowText}" 
11.                               Text="{Binding Path=Text, Mode=TwoWay}"/>
12.    </Grid>
13.  </DataTemplate>
14.</telerik:GridViewDataColumn.CellEditTemplate>

 

I can't find the RichTextBox in C# by name and assign it to the dictionary , such as:

1.ProtocolRowTextBox.SpellChecker = _localViewModel.DocumentSpellChecker;

 

 

 

2 Answers, 1 is accepted

Sort by
0
Accepted
Dinko | Tech Support Engineer
Telerik team
answered on 17 Jul 2019, 11:19 AM
Hello Harald,

Thank you for the provided code snippet.

To get the RichTextBox in the edit template, you can subscribe to the PreparedCellForEdit event of the RadGridView. Inside the event handler, you can get the first element in the cell from the EditingElement property in the event arguments. In your case, it will be the Grid. To get the RadRichTextBox you can just use the Children collection of the control. The following code snippet demonstrates what I have in mind.
private void GridView_PreparedCellForEdit(object sender, GridViewPreparingCellForEditEventArgs e)
{
    var grid = e.EditingElement as Grid;
    var ProtocolRowTextBox = grid.Children[0] as RadRichTextBox;
    // ProtocolRowTextBox.SpellChecker = _localViewModel.DocumentSpellChecker;
}

Regards,
Dinko
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Harald
Top achievements
Rank 2
answered on 17 Jul 2019, 03:01 PM
Works fine. Thank you.
Tags
GridView
Asked by
Harald
Top achievements
Rank 2
Answers by
Dinko | Tech Support Engineer
Telerik team
Harald
Top achievements
Rank 2
Share this question
or