Button in grid raw

7 posts, 0 answers
  1. ron klod
    ron klod avatar
    35 posts
    Member since:
    Feb 2010

    Posted 11 Aug 2010 Link to this post

    Hi,

    I have a button inside a raw, the button has a click event,

    my question is how from the button click event handler I get a reference to the raw that contains it

  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 11 Aug 2010 Link to this post

    Hello ron klod,

    You can use the extension method ParentOfType<>. For example:

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        var senderElement = e.OriginalSource as FrameworkElement;
        var row = senderElement.ParentOfType<GridViewRow>();
     
        if (row != null)
        {
            //Implement your custom logic here.
        }              
    }

    You can find more information about the extension method ParentOfType<> as well as the corresponding one ChildrenOfType<> in this blog post.


    Sincerely yours,
    Maya
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
  4. Laura Edwards
    Laura Edwards avatar
    25 posts
    Member since:
    Jun 2010

    Posted 11 Aug 2010 Link to this post

    I have a similar issue.

    I am opening up a radwindow when I click a button in the grid row. I would like to pass one of the row details into the rad window where a radcombobox will pick up that detail as the selected value.

    I am using MVVM. Is there a way to do this?
  5. ron klod
    ron klod avatar
    35 posts
    Member since:
    Feb 2010

    Posted 11 Aug 2010 Link to this post

    you soluyion doesn not work,

    this does not compile: var row = senderElement.ParentOfType<GridViewRow>();
  6. Tyree
    Tyree avatar
    105 posts
    Member since:
    Dec 2006

    Posted 11 Aug 2010 Link to this post

    Ron, ParentOfType<> extension lives in Telerik.Windows.Controls.dll under namespace Telerik.Windows.Controls.UIElementExtensions

    Make sure you have the appropriate references and usings.
  7. Tyree
    Tyree avatar
    105 posts
    Member since:
    Dec 2006

    Posted 11 Aug 2010 Link to this post

    Laura,

    I would (and have) make a new xaml for your RadWindow, in doing this you can create its own VM and the properties you need to hand the data to it.

    Something like (this is the DetailsWindow.xaml)

    <telerik:RadWindow
        x:Class="MyNamespace.DetailsWindow"
        mc:Ignorable="d"
        d:DesignHeight="300" d:DesignWidth="400">
         
        <Grid x:Name="LayoutRoot" Background="White">
    <!-- make it look as desired -->
        </Grid>
    </telerik:RadWindow>

    then in the codebehind (DetailsWindow.xaml.cs) something like
    using System.Windows.Controls;
    using Telerik.Windows.Controls;
     
    namespace MyNamespace
        public partial class DetailsWindow : RadWindow
        {
            public DetailsWindow()
            {
                InitializeComponent();
            }
     
            public object SomeIncomingItem { get; set; }
        }
    }

    Then if you create a new DetailsWindow you can do DetailsWindow.SomeIncomingItem = foo. So your button click could create a new DetailsWindow and set the value. This doesn't really maintain MVVM and is merely one possibility. Technically your RadWindow is another V and should have a VM. Your main V could trigger your VM through a command to make the VM for the RadWindow which fires an event that your V is listening to and passes in the VM for the RadWindow. The event then creates a RadWindow with the VM backing it.

    Does that make sense?
  8. Laura Edwards
    Laura Edwards avatar
    25 posts
    Member since:
    Jun 2010

    Posted 11 Aug 2010 Link to this post

    It kind of makes sense. I'm still a little confused.

    In MainPage.xaml.cs (where MainPage.xaml contains the gridview), I call a new window:
    deleteCateoryWindow = new DeleteCategory();
    deleteCateoryWindow.ShowDialog();
    deleteCategoryWindow is the window where I have the DDL that I want to populate with the selected value from the grid. Also the DDL is bound to a list in it's view model. How do I pass the grid's selected Item to the window?

    Thanks for your help.

Back to Top
DevCraft banner