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

Acessing TextBox (within GroupFooterTemplate) parent from codebehind

3 Answers 34 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Leonardo
Top achievements
Rank 1
Leonardo asked on 07 Mar 2016, 09:50 PM
Hello,

I'm using a RadGridView, and in it's footer, a textbox element inside a GroupFooterTemplate. Can I, from codebehind, in a TextBox event (e.g. TextChanged) somehow access the GridView that contains my TextBox? When I check the sender's properties, the parent is null.

Also, can I somehow access the group information and the other groups' TextBoxes?

Any help would be appreciated.

3 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 08 Mar 2016, 02:22 PM
Hello Leonardo,

This requirement can be achieved by using the ParentOfType extension method. Basically, it traverses the visual tree recursively searching for an object of given type.
var grid = (sender as TextBox).ParentOfType<GridViewDataControl>();

However, RadGridView is a data-bound control and accessing its visual elements directly is not recommended. Can you please share some details on your need to access the control in the TextChanged event of the TextBox?

Regards,
Stefan X1
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Leonardo
Top achievements
Rank 1
answered on 09 Mar 2016, 01:58 PM

Hello, Stefan.

I wanted to access the group's key property, but I managed to do it by using the following:

Tag="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type telerik:GridViewGroupRow}}, Path=Group.Key}"

So, basically, I get the Tag property's value from the sender (TextBox) in the CodeBehind.

Thanks a lot for your help, and I'm sorry for opening another thread. I couldn't find this one after posting it, so I wasn't sure if I had really posted. That won't happen again.

0
Stefan
Telerik team
answered on 10 Mar 2016, 03:44 PM
Hello Leonardo,

I am glad you've managed to find a solution for your requirement.

Feel free to contact us in case you have any other questions on our controls.

All the best,
Stefan X1
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
GridView
Asked by
Leonardo
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Leonardo
Top achievements
Rank 1
Share this question
or