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

How to get the Parent of Button which is in DataTempalte

4 Answers 96 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Patryk Kubiela
Top achievements
Rank 1
Patryk Kubiela asked on 05 Jul 2010, 08:20 AM

For example, I have column like this...

<telerikGridView:GridViewDataColumn  x:Name="Edit_Edit1">  
                        <telerikGridView:GridViewDataColumn.CellTemplate> 
                            <DataTemplate> 
                                 <Button Content="Edycja" Style="{StaticResource greenMediaButton}" Click="EditButton1_Click"/>  
                            </DataTemplate> 
                        </telerikGridView:GridViewDataColumn.CellTemplate> 
                    </telerikGridView:GridViewDataColumn> 

and in EditButton1_Click event, for silverlight DataGrid I did it so...

Button bt = sender as Button;  
            KronSiteTable kst = bt.DataContext as KronSiteTable;  
            DataGridCell cellButton = bt.Parent as DataGridCell;  
            DataGridCellsPresenter cells = cellButton.Parent as DataGridCellsPresenter; 

but when i use GridViewCell:

GridViewCell cellButton = bt.Parent as GridViewCell; 

i get the null Parent property.

About what I mean.
I want to access the row in which there is a button you click on it
, to have the ability to modify individual cells.


Thank you in advance for your reply.
Patryk.

4 Answers, 1 is accepted

Sort by
0
Accepted
Vlad
Telerik team
answered on 05 Jul 2010, 08:23 AM
Hello Patryk,

 Why not use ParentOfType<>() extension method instead? This is part of Telerik.Windows.Controls namespace. Here is an example:

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

Sincerely yours,
Vlad
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
Patryk Kubiela
Top achievements
Rank 1
answered on 05 Jul 2010, 11:03 AM
Thank you for your fast response !
This works great !

I send regards.
Patryk.
0
jean michel
Top achievements
Rank 1
answered on 09 Aug 2010, 08:28 PM
Hello,

I am with the same problem.

But in my button the ParentOfType property does not exist .

My version is SL3.

Thanks..!!
0
jean michel
Top achievements
Rank 1
answered on 09 Aug 2010, 09:41 PM
Hello,

It lacked import using

using

 

 

Telerik.Windows.Controls;

Thanks!!!

 

Tags
GridView
Asked by
Patryk Kubiela
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Patryk Kubiela
Top achievements
Rank 1
jean michel
Top achievements
Rank 1
Share this question
or