Solved

WPF Datagrid Button

Posted on 2011-03-23
2
578 Views
Last Modified: 2012-05-11
I have added a button to a data grid like below but how do I handle the click event?

  <DataGridTemplateColumn>
                                <DataGridTemplateColumn.CellTemplate>
                                        <DataTemplate>
                                        <Button Content="Edit" Name="btnEdit" >                                           
                                        </Button>
                                        </DataTemplate>
                                 </DataGridTemplateColumn.CellTemplate>
                            </DataGridTemplateColumn>
0
Comment
Question by:Kevin Robinson
2 Comments
 
LVL 16

Accepted Solution

by:
Imran Javed Zia earned 500 total points
ID: 35197092
Hi, you can either use RowCommand event and pass the CommandName in button as
<DataGridTemplateColumn>
                                <DataGridTemplateColumn.CellTemplate>
                                        <DataTemplate>
                                        <Button Content="Edit" Name="btnEdit" CommandName="Edit">                                          
                                        </Button>
                                        </DataTemplate>
                                 </DataGridTemplateColumn.CellTemplate>
                            </DataGridTemplateColumn>
Or you can uas add event Handler directly as
<DataGridTemplateColumn>
                                <DataGridTemplateColumn.CellTemplate>
                                        <DataTemplate>
                                        <Button Content="Edit" Name="btnEdit" OnClick="btnEdit_click" >                                           
                                        </Button>
                                        </DataTemplate>
                                 </DataGridTemplateColumn.CellTemplate>
                            </DataGridTemplateColumn>
0
 
LVL 3

Author Comment

by:Kevin Robinson
ID: 35197239
OK got that.. How do I then get the value (item) of the row.

0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question