Click here to Skip to main content
15,885,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a DataGrid with RichTextBox inside the datatemplate. How do I found the RichTextBox in a button click event, something like we use FindControl in asp.net. My requirement is to insert the text at cursor position in RichTextBox. Please suggest me how can I do this.

HTML
<data:DataGrid IsReadOnly="False" x:Name="dGridExpressions" AutoGenerateColumns="False">
     <data:DataGrid.Columns>
             <data:DataGridTextColumnBinding="{Binding Steps}" Header="Steps"/>
                <data:DataGridTemplateColumn x:Name="ContentColm" Header="Expression" IsReadOnly="True">
                                		<data:DataGridTemplateColumn.CellEditingTemplate>
   <DataTemplate>
      <RichTextBox x:Name="ContentText" MinWidth="610" 		BorderThickness="1" KeyDown="TextBox_KeyDown" Margin="1">
      <Paragraph>
            <Run Text="{Binding Path=RuleCondition, Mode=TwoWay}" />
       </Paragraph>
       </RichTextBox>
                                           
       </DataTemplate>
                                		</data:DataGridTemplateColumn.CellEditingTemplate>
</data:DataGridTemplateColumn>

                                </data:DataGrid.Columns>
                            </data:DataGrid>
Posted

1 solution

Why don't you just use binding to get the appropriate values from the richtextbox instead of using the keydown event.
This would be the correct way to proceed.
 
Share this answer
 
Comments
m@dhu 1-Feb-12 0:58am    
I used binding itself. Keydown event for different purpose. How do I insert text say some multiple times at different cursor positions and in different rows?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900