Select row on edit button click

15 posts, 1 answers
  1. Shabbir Hussain
    Shabbir Hussain avatar
    9 posts
    Member since:
    Jan 2010

    Posted 15 Jan 2010 Link to this post

    Sir,
            I am using silverlight 2010 telerik RadGridView. I am customizing grid view and put two simple buttons for Edit and Delete for opening  separate Forms for editing and deleting.

    Kindly you can tell me how to mark row as selected when I am clicking on buttons unfortunately when I am clicking on button the raw was not marks as selected.

     

     

  2. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 15 Jan 2010 Link to this post

    Hello Shabbir Hussain,

    Yo could try the following code for your Click event handlers:

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        var senderElement = e.OriginalSource as FrameworkElement;
        var row = senderElement.ParentOfType<GridViewRow>();
      
        if (row != null)
            row.IsSelected = true;
    }


    Greetings,
    Milan
    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.
  3. DevCraft banner
  4. Shabbir Hussain
    Shabbir Hussain avatar
    9 posts
    Member since:
    Jan 2010

    Posted 15 Jan 2010 Link to this post

    after implementing you sample code i am facing this error, how to remove this error.

    'System.Windows.FrameworkElement' does not contain a definition for 'ParentOfType' and no extension method 'ParentOfType' accepting a first argument of type 'System.Windows.FrameworkElement' could be found (are you missing a using directive or an assembly reference?


  5. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 15 Jan 2010 Link to this post

    Hello Shabbir Hussain,

    Please include the namespace Telerik.Windows.Controls  to gain access to the extension method ParentOfType.

    e.g.
    using Telerik.Windows.Controls;

    Best wishes,
    Pavel Pavlov
    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.
  6. Shabbir Hussain
    Shabbir Hussain avatar
    9 posts
    Member since:
    Jan 2010

    Posted 15 Jan 2010 Link to this post

    i also share my code so you can solve  my problem in a seconds

               <telerikControls:RadGridView x:Name="radGrid1" CurrentCellChanged="radGrid1_CurrentCellChanged" SelectionChanged="radGrid1_SelectionChanged"  AutoGenerateColumns="False">
                    <telerikControls:RadGridView.Columns>
                        <telerikControls:GridViewDataColumn Header="MemberID" DataMemberBinding="{Binding MemberID}"></telerikControls:GridViewDataColumn>
                        <telerikControls:GridViewDataColumn Header="Name" DataMemberBinding="{Binding Name}"></telerikControls:GridViewDataColumn>
                        <telerikControls:GridViewDataColumn  HeaderTextAlignment="Center"  Header="Events" DataMemberBinding="{Binding MemberID, Mode=TwoWay}" TextAlignment="Center">
                            <telerikControls:GridViewDataColumn.CellTemplate>
                                <DataTemplate>
                                    <Button Name="btnEdit" CommandParameter="{Binding MemberID}"    Content="Edit" Width="100" Height="25" Click="btnEdit_Click"></Button>

                                </DataTemplate>
                            </telerikControls:GridViewDataColumn.CellTemplate>
                        </telerikControls:GridViewDataColumn>
                    </telerikControls:RadGridView.Columns>
                   
                </telerikControls:RadGridView>

  7. Answer
    Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 19 Jan 2010 Link to this post

    Hello Shabbir Hussain,

    The sample project attached illustrates the approach from the previous posts in action .  On clicking a button in the row , the containing row gets selected.

    Kind regards,
    Pavel Pavlov
    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.
  8. Ravindranath Wickramanayake
    Ravindranath Wickramanayake avatar
    5 posts
    Member since:
    Jan 2010

    Posted 28 Mar 2010 Link to this post

    How do you use Interaction.Triggers with the edit button inside a telerikGridView:GridViewColumn

    my code bellow is as bellow. it doesn't work

    <telerikGridView:RadGridView Height="100" telerik:StyleManager.Theme="Windows7" x:Name="grdAdditionalMembers"  
                            Background="Transparent" CanUserFreezeColumns="False" ColumnsWidthMode="Fill" 
                            MultipleSelect="False" AutoExpandGroups="True" ShowGroupPanel="False" AutoGenerateColumns="False" 
                            ItemsSource="{Binding Und.AdditionalMembers}"
                    <telerikGridView:RadGridView.Columns> 
                         <telerikGridView:GridViewDataColumn     Header="First Name" Width="150"   DataMemberBinding="{Binding FirstName}"  
                              IsReadOnly="True" IsGroupable="True" IsFilterable="True"/> 
                         <telerikGridView:GridViewDataColumn     Header="Last Name" Width="150"   DataMemberBinding="{Binding LastName}"  
                                                              IsReadOnly="True" IsGroupable="True" IsFilterable="True"  />   
                        <telerikGridView:GridViewDataColumn     Header="Sex" Width="150"   DataMemberBinding="{Binding Sex}"  
                                                              IsReadOnly="True" IsGroupable="True" IsFilterable="True"  /> 
                        <telerikGridView:GridViewDataColumn     Header="DOB" Width="150"   DataMemberBinding="{Binding DOB}"  
                                                              IsReadOnly="True" IsGroupable="True" IsFilterable="True"  /> 
                        <telerikGridView:GridViewColumn> 
                            <telerikGridView:GridViewColumn.CellTemplate> 
                                <DataTemplate> 
                                    <StackPanel> 
                                        <Button Margin="2" Height="20" Width="40" Content="edit"
                                                <i:Interaction.Triggers> 
                                                    <i:EventTrigger EventName="Click"
                                                        <si:InvokeDataCommand Command="{Binding RaiseEdit, Mode=OneWay}"/> 
                                                    </i:EventTrigger> 
                                                </i:Interaction.Triggers> 
                                            </Button> 
                                    </StackPanel> 
                                </DataTemplate> 
                            </telerikGridView:GridViewColumn.CellTemplate> 
                        </telerikGridView:GridViewColumn>                                      
                    </telerikGridView:RadGridView.Columns> 
                   </telerikGridView:RadGridView> 

  9. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 31 Mar 2010 Link to this post

    Hi Ravindranath Wickramanayake,

    Well, the DataContext for InvokeDataCommand will be a data item. the Are you sure that the data items have RaiseEdit property? Maybe you are expecting a different DataContext?

    I have attached a sample project that uses InvokeDataCommand.


    Kind regards,
    Milan
    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.
  10. Carlos Queiros
    Carlos Queiros avatar
    1 posts
    Member since:
    Feb 2008

    Posted 16 Aug 2010 Link to this post

    Hi,
    There's any way to do this with a behavior?

    I'm doing this

    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Interactivity;
    //using Microsoft.Expression.Interactivity.Core;
    using Telerik.Windows.Controls;
    using Telerik.Windows.Controls.GridView;

    namespace Senun.Controls.Silverlight
    {
    public class SelectGridViewRowOnClick : Behavior<FrameworkElement>
    {
    public SelectGridViewRowOnClick()
    {

    }

    protected override void OnAttached()
    {
    base.OnAttached();

                this.AssociatedObject.KeyDown += new KeyEventHandler(AssociatedObject_KeyDown);
    }

            void AssociatedObject_KeyDown(object sender, KeyEventArgs e)
            {
                var _row = this.AssociatedObject.ParentOfType<GridViewRow>();
            }

    protected override void OnDetaching()
    {
    base.OnDetaching();

                this.AssociatedObject.KeyDown -= AssociatedObject_KeyDown;
    }
    }
    }

    and it says that there's no implicit conversion from GridViewRow to DependencyObject
  11. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 17 Aug 2010 Link to this post

    Hi Carlos Queiros,

    Could you please provide us with more information about the functionality that you are trying to implement? 


    All the best,
    Milan
    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
  12. Herb
    Herb avatar
    3 posts
    Member since:
    Dec 2010

    Posted 19 May 2011 Link to this post

    I was having a similar issue, clicking a Button in a column does not cause the row to be selected.
    I used the code from commands.zip sample which worked...

    ((

     

    Button)sender).ParentOfType<GridViewRow>().IsSelected = true;

     


    I am now moving my code to a ViewModel. My command is invoked and I can pass the bound data object as a parameter but I would also like to select the row. How do I do this from a ViewModel?

    Regards,
    Herb

     
  13. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 20 May 2011 Link to this post

    Hello Herb,

    You could create SelectedItems collection on your ViewModel and you can simply add the respective items to this collection. Once this is done you will need a mechanism that synchronizes the SelectedItems of your ViewModel with the ones of the grid. Luckily we have a blog post for that.

    Hope this helps.



    Greetings,
    Milan
    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
  14. Nalini
    Nalini avatar
    9 posts
    Member since:
    Apr 2015

    Posted 23 Apr 2015 Link to this post

    I had same requirement.

    below code works but it calls function 2 times as there are two buttons in a row (but in different column)

     

     public void btnEdit_Click(object sender, MouseButtonEventArgs e)
            {
                if (sender == null)
                    return;
                var senderElement = e.OriginalSource as FrameworkElement;
                var row = senderElement.ParentOfType<GridViewRow>();
                XeRecord rec = row.Item as XeRecord;
                selectStaff(rec);
            }

     

     

     

     

  15. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 24 Apr 2015 Link to this post

    Hi,

    I am not sure how the shared code calls function 2 times, would you please clarify which function do you mean? As this thread is quite old, I would suggest you to open a new support ticket under the respective product category and provide some more details on the exact case.

    Regards,
    Dimitrina
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  16. Nalini
    Nalini avatar
    9 posts
    Member since:
    Apr 2015

    Posted 24 Apr 2015 in reply to Dimitrina Link to this post

    Hello, Dimitrina!

     

    I have opened new thread for my issue. Please see it on 

    http://www.telerik.com/forums/click-event-handler-in-dynamic-data-template-in-grid-view-does-not-work-correctly

Back to Top
DevCraft banner