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

[Solved] Parent of button in a column is null

2 Answers 141 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Marc Roussel
Top achievements
Rank 1
Marc Roussel asked on 09 Dec 2009, 07:38 PM
Hi,

With this column here which is working all right, I have the button and the event is fired.
I'm trying to get the row from which the buttin is in and the parent of the button is null.  Any idea ?

   <telerikGridView:RadGridView.Columns>
    <telerikGridView:GridViewDataColumn>
     <telerikGridView:GridViewColumn.CellTemplate>
      <DataTemplate>
       <Button Content="Effacer" Click="DeleteTime_Click">
       </Button>
      </DataTemplate>
     </telerikGridView:GridViewColumn.CellTemplate>
    </telerikGridView:GridViewDataColumn>
   </telerikGridView:RadGridView.Columns>

Trying to get the row with this line :

GridViewRow Row = ((Button)sender).Parent as GridViewRow;

 

 

 

 

 

 


I have the latest build, 2009.3.1127

2 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 10 Dec 2009, 06:58 AM
Hi,

 You can use ParentOfType<>()  to achieve your goal:

         var row = ((Button)sender).ParentOfType<GridViewRow>();

This is extension method available in Telerik.Windows.Controls namespace.


All the best,
Vlad
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
Marc Roussel
Top achievements
Rank 1
answered on 10 Dec 2009, 06:14 PM
Awesome it works perfectly.  Often people doesn't know this little hint so I would like to say to people that doesn't see ParentOfType that they need to add a using statement because you can't make things like

((Button)sender)Telerik.Windows.Controls.ParentOfType...

I often see things like this in the forum since a few times.  It's good to mention the namespace as you did.

I sent an email to my superiour to go on with the purchase of the lisences :)
I think your grid is excellent and your support is good !

Thank you
Tags
GridView
Asked by
Marc Roussel
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Marc Roussel
Top achievements
Rank 1
Share this question
or