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

How to click a button directly without focus on a CellTemptate of a sfDataGrid

Hi,
My use case is : I have a sfDatagrid, with a GridTemplateColumn containing a single button.
To launch the method behind the button I have to :
- click one time to focus the row
- click again to launch the method behind the button
Is there a way to achieve it (Focus + button click) in one single click ?
It is important to set the focus because the button role is to open a "More Details" for the row.
Regards,

8 Replies

JS Jayapradha S Syncfusion Team April 11, 2016 04:43 AM UTC

Hi Marquant,

Thank you for contacting Syncfusion Support.

We have analyzed your query. You can set the focus to button without focus on a celltemplate by setting Syncfusion.FocusManagerHelper.FocusedElement to true as shown below,

Code Example:

 <Syncfusion:GridTemplateColumn>

                    <Syncfusion:GridTemplateColumn.CellTemplate>

                        <DataTemplate>

                            <Button Width="Auto" Syncfusion:FocusManagerHelper.FocusedElement="True" 

                                    Height="Auto"

                                    Click="Button_Click"

                                    Content="Call” />

                        </DataTemplate>

                    </Syncfusion:GridTemplateColumn.CellTemplate>

  </Syncfusion:GridTemplateColumn>


Please refer the below KB Link,
KB Link: https://www.syncfusion.com/kb/3206/how-to-edit-sfdatagrid-template-column-by-single-tap

Regards,
Jayapradha



JS Jayapradha S Syncfusion Team April 11, 2016 04:43 AM UTC

Hi Marquant,

Thank you for contacting Syncfusion Support.

We have analyzed your query. You can set the focus to button without focus on a celltemplate by setting Syncfusion.FocusManagerHelper.FocusedElement to true as shown below,

Code Example:

 <Syncfusion:GridTemplateColumn>

                    <Syncfusion:GridTemplateColumn.CellTemplate>

                        <DataTemplate>

                            <Button Width="Auto" Syncfusion:FocusManagerHelper.FocusedElement="True" 

                                    Height="Auto"

                                    Click="Button_Click"

                                    Content="Call” />

                        </DataTemplate>

                    </Syncfusion:GridTemplateColumn.CellTemplate>

  </Syncfusion:GridTemplateColumn>


Please refer the below KB Link,
KB Link: https://www.syncfusion.com/kb/3206/how-to-edit-sfdatagrid-template-column-by-single-tap

Regards,
Jayapradha



MC MARQUANT Cédric April 11, 2016 04:48 AM UTC

Thanks ! 

It works perfectly.

Regards,


JS Jayapradha S Syncfusion Team April 12, 2016 05:03 AM UTC

Hi Marquant

Thank you for your update.

Please let us know if you require any other assistance.

Regards,
Jayapradha


HJ Helmut Jilka June 19, 2018 11:45 AM UTC

I have a similar problem, but I have 2 buttons inside a DataGrid Cell ("moving line up/down" buttons)
Using syncfusion:FocusManagerHelper.FocusedElement="True" works fine for one of the buttons but clicking the second button works only at the second click.

Is there a solution for this as well?






SJ Sathiyathanam Jeyakumar Syncfusion Team June 20, 2018 07:09 AM UTC

Hi Marquant, 
 
We have analyzed your query and you can achieve your requirement by set the focus for the both buttons inside the DataGridCell. Please find the below code snippets to set the focus for the buttons. 
 
Code snippets : 
 
<syncfusion:GridTemplateColumn > 
                    <syncfusion:GridTemplateColumn.CellTemplate> 
                        <DataTemplate> 
                            <Grid> 
                                <Grid.ColumnDefinitions> 
                                    <ColumnDefinition/> 
                                    <ColumnDefinition/> 
                                </Grid.ColumnDefinitions> 
                                <Button x:Name="button1" Grid.Column="0" Click="button1_Click" Height="20" syncfusion:FocusManagerHelper.FocusedElement="True" Content="B1"/> 
                                <Button x:Name="button2" Grid.Column="1" Click="button2_Click" Height="20" syncfusion:FocusManagerHelper.FocusedElement="True" Content="B2"/> 
                            </Grid> 
                        </DataTemplate> 
                    </syncfusion:GridTemplateColumn.CellTemplate> 
</syncfusion:GridTemplateColumn> 
 
You can download the testing sample from the below location. 
 
 
If the issue is still persisting, could you please provide the sample to us based on your application, this will help us to analyze further and provide the better solution to you. 
 
 
Regards, 
Sathiyathanam 



YA yanghaibo February 5, 2022 03:51 PM UTC

hello Sathiyathanam,

I just download the sample EditingTemplateColumn_WPF-1364933297141210955.zip , and add two messagebox in the two button_click event. When I click the button1, the messagebox show immediately, but when I click button2, the messagebox only show at the second click.

Regards, 
Yanghaibo




VS Vijayarasan Sivanandham Syncfusion Team February 7, 2022 03:32 PM UTC

Hi Yanghaibo,

 
Your requirement to click a buttons directly in SfDataGrid can be achieved by creating custom GridCellTemplateRenderer and customize the SetFocus method as shown below. 

this.dataGrid.CellRenderers.Remove("Template"); 
this.dataGrid.CellRenderers.Add("Template", new GridCellTemplateExt()); 
 
public class GridCellTemplateExt : GridCellTemplateRenderer 
{ 
        protected override void SetFocus(FrameworkElement uiElement, bool needToFocus) 
        { 
            if (!needToFocus) 
                DataGrid.Focus(); 
        } 
} 




Please let us know if you have any concerns in this. 

Regards, 
Vijayarasan S 


Loader.
Up arrow icon