Acessing TextBox (within GroupFooterTemplate) parent from codebehind

4 posts, 0 answers
  1. Leonardo
    Leonardo avatar
    7 posts
    Member since:
    Mar 2016

    Posted 07 Mar Link to this post

    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.
  2. Stefan X1
    Admin
    Stefan X1 avatar
    514 posts

    Posted 08 Mar Link to this post

    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. Leonardo
    Leonardo avatar
    7 posts
    Member since:
    Mar 2016

    Posted 09 Mar in reply to Stefan X1 Link to this post

    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.

  5. Stefan X1
    Admin
    Stefan X1 avatar
    514 posts

    Posted 10 Mar Link to this post

    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.
Back to Top