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

Select row on edit button click

16 Answers 621 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Shabbir Hussain
Top achievements
Rank 1
Shabbir Hussain asked on 15 Jan 2010, 11:37 AM

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.

 

 

16 Answers, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 15 Jan 2010, 11:57 AM
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.
0
Shabbir Hussain
Top achievements
Rank 1
answered on 15 Jan 2010, 12:16 PM
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?


0
Pavel Pavlov
Telerik team
answered on 15 Jan 2010, 12:32 PM
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.
0
Shabbir Hussain
Top achievements
Rank 1
answered on 15 Jan 2010, 12:36 PM
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>

0
Accepted
Pavel Pavlov
Telerik team
answered on 19 Jan 2010, 11:19 AM
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.
0
Ravindranath Wickramanayake
Top achievements
Rank 1
answered on 29 Mar 2010, 04:26 AM
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> 

0
Milan
Telerik team
answered on 31 Mar 2010, 11:55 AM
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.
0
Carlos Queiros
Top achievements
Rank 1
answered on 16 Aug 2010, 01:23 PM
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
0
Milan
Telerik team
answered on 17 Aug 2010, 02:22 PM
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
0
Herb
Top achievements
Rank 1
answered on 19 May 2011, 10:29 PM
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

 
0
Milan
Telerik team
answered on 20 May 2011, 09:17 AM

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
0
Nalini
Top achievements
Rank 1
answered on 23 Apr 2015, 06:05 PM

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);
        }

 

 

 

 

0
Dimitrina
Telerik team
answered on 24 Apr 2015, 02:01 PM
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.

 
0
Nalini
Top achievements
Rank 1
answered on 24 Apr 2015, 04:36 PM

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

0
Piotr
Top achievements
Rank 1
answered on 13 Jul 2018, 01:33 PM

I had the same problem as Shabbir Hussain. I wanted to select row when clicking on the button that was inside the row on RadGridView. BUT I wanted also to not break the default way that grid view works. E.g. in provided code by Milan you end up with 2 rows selected if you had a row selected before clicking on the button.

For others - here is modified version that works for me:

private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
    var senderElement = e.OriginalSource as FrameworkElement;
    var row = senderElement.ParentOfType<GridViewRow>();
 
    if (row != null)
    {
        row.RaiseEvent(new MouseButtonEventArgs(Mouse.PrimaryDevice, 0, MouseButton.Left)
        {
            RoutedEvent = Mouse.MouseDownEvent,
            Source = this,
        });
    }
}
0
Piotr
Top achievements
Rank 1
answered on 13 Jul 2018, 01:37 PM
I didn't even notice it's a silverlight forum. Worth to add, I'm working with WPF.
Tags
GridView
Asked by
Shabbir Hussain
Top achievements
Rank 1
Answers by
Milan
Telerik team
Shabbir Hussain
Top achievements
Rank 1
Pavel Pavlov
Telerik team
Ravindranath Wickramanayake
Top achievements
Rank 1
Carlos Queiros
Top achievements
Rank 1
Herb
Top achievements
Rank 1
Nalini
Top achievements
Rank 1
Dimitrina
Telerik team
Piotr
Top achievements
Rank 1
Share this question
or