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. Image for the cookie policy date
close icon

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

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

3 Replies

BR Balamurugan Rajaraman Syncfusion Team 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 
 



SC Sam Chan 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


BR Balamurugan Rajaraman Syncfusion Team 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 


Loader.
Live Chat Icon For mobile
Up arrow icon