We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Button in CellTemplate not receiving the first click event until cell is activated

Thread ID:

Created:

Updated:

Platform:

Replies:

130047 Apr 18,2017 12:46 PM UTC Apr 21,2017 04:31 AM UTC WPF 3
loading
Tags: SfDataGrid
Sam Chan
Asked On April 18, 2017 12:46 PM UTC

Hi,

I've loaded a button in the CellTemplate of a GridTemplateColumn. The button has a Click event handler but it is not called when the button is first clicked. Instead the cell containing the button is activated (become selected) after the first click and then the Click event handler is called when the button is clicked again after the cell is activated. How do I enable the button to receive the first click event even when the cell is not activated? For example, the checkbox control of the GridCheckBoxColumn can be checked or unchecked on the first click even when the cell is not activated. I tried:

<syncfusion:GridTemplateColumn.CellTemplate>

     <DataTemplate>

          <Button syncfusion:VisualContainer.WantsMouseInput="True" Click="Button_Click"/>

     </DataTemplate>

</syncfusion:GridTemplateColumn.CellTemplate>

Regards,

Sam

Balamurugan Rajaraman [Syncfusion]
Replied On April 19, 2017 12:50 PM UTC

Hi Sam,  
  
Thank you for contact Syncfusion support.  
  
We have analyzed your query.  You can achieve your requirement by override the  SetFocus() method in GridCellTemplateRenderer class as like below code sample 
  
Code Snippet:  
 
  
this.datagrid.CellRenderers.Remove("TemplateExt");  
this.datagrid.CellRenderers.Add("TemplateExt"new GridCellTemplateExt());  
  
public class GridCellTemplateExt : GridCellTemplateRenderer  
{  
    protected override void SetFocus(FrameworkElement uiElement, bool needToFocus)  
    {  
        if (!needToFocus)  
            DataGrid.Focus();  
    }  
}  
  
In the below sample, we have created the custom column and custom renderer from GridTemplateColumn and focus the element to grid cell.  
  
 
Regards, 
Balamurugan R 
 


Sam Chan
Replied On April 20, 2017 10:51 AM UTC

Hi Balamurugan,

Thank you for the solution. I've adapted the code to achieve the functionality that I need.

Regards,

Sam

Balamurugan Rajaraman [Syncfusion]
Replied On April 21, 2017 04:31 AM UTC

Hi Sam 
 
Thank you for the update. 
Please let us know further assistance on this. 
 
Regards, 
Balamurugan R 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;