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

[Solved] Accessing Textbox Control from code

4 Answers 140 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.
david ocasio
Top achievements
Rank 1
david ocasio asked on 15 Oct 2009, 02:56 AM

Is it possilbe to reference a textbox that has been included in the datatemplate of a celltemplate at runtime
from the rowloaded event. FindName doesn't do it.

my simplified xaml for the column is as so

<telerikGridView:RadGridView.Columns>
    <telerikGridView:RadGridView.Columns>
       <telerikGridView:GridViewDataColumn.CellTemplate>
            <DataTemplate >
                <TextBox Text="{Binding QtyOnHand,Mode=TwoWay}" TextAlignment="Right"  x:Name="TargetTextBox"  />
            </DataTemplate>
        </telerikGridView:GridViewDataColumn.CellTemplate>
    </telerikGridView:GridViewDataColumn>
</telerikGridView:RadGridView.Columns>   

thanks
dco

4 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 15 Oct 2009, 06:58 AM
Hi david,

Why not use Loaded event of the TextBox itself? Sender argument of the event handler is the TextBox and you can access your data object using DataContext property.

Kind regards,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
david ocasio
Top achievements
Rank 1
answered on 15 Oct 2009, 10:29 AM

Well

 

I may be doing something stupid or at least different.

I thought of using the loaded events of the textboxes But I am Inherting your grid
When i declare the event in xaml it assumes the event is in the hosting page.
I would prefer for the event to hit the instance of the inherting class.
So the event code is encapsulated inside my class.

Thus my use of the rowloaded event to try and grab the textbox instead.

is there a way around that
a syntax i am not aware of

0
Accepted
Vlad
Telerik team
answered on 15 Oct 2009, 11:36 AM
Hello david,

In this case you use our powerful extension methods to find desired control in desired cell in RowLoaded event.

Best wishes,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
david ocasio
Top achievements
Rank 1
answered on 15 Oct 2009, 11:56 AM
Perfect Vlad,

Thats exactly what i need.

Thanks for you help
you guys rock
dco
Tags
GridView
Asked by
david ocasio
Top achievements
Rank 1
Answers by
Vlad
Telerik team
david ocasio
Top achievements
Rank 1
Share this question
or