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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

SfDataGrid column with multiple buttons

Thread ID:

Created:

Updated:

Platform:

Replies:

144140 Apr 22,2019 09:15 AM UTC Apr 23,2019 11:29 AM UTC WPF 1
loading
Tags: SfDataGrid
Brijesh
Asked On April 22, 2019 09:15 AM UTC

Hi Team,

I am experimenting with the SfDataGrid and would like to know how to assign multiple buttons in a sfdatagrid column. Here number of buttons for a column might be different for each row. Please help on this issue.

Kind regards,
Brijesh.



Dinesh Babu Yadav [Syncfusion]
Replied On April 23, 2019 11:29 AM UTC

Hi Brijesh, 
 
Thank you for contacting Syncfusion Support. 
 
We have analyzed your query to have different number of buttons in each row of SfDataGrid. And your requirement can be achieved by using GridTemplateColumn and CellTemplateSelector as like below code snippet 
 
C#: 
public class GridCellTemplateSelectorEXt : DataTemplateSelector 
    { 
        public override DataTemplate SelectTemplate(object item, DependencyObject container) 
        { 
            if (item == null) 
                return null; 
 
            if (((item as OrderInfo).OrderID % 2) == 0) 
                return App.Current.MainWindow.Resources["template1"] as DataTemplate; 
            else 
                return App.Current.MainWindow.Resources["template2"] as DataTemplate; 
        } 
   } 
 
XAML: 
<Window.Resources> 
        <DataTemplate x:Key="template1"> 
            <StackPanel Orientation="Horizontal"> 
                <Button Content="B1" Margin="5"/> 
                <Button Content="B2" Margin="5"/> 
                <Button Content="B3" Margin="5"/> 
            </StackPanel> 
        </DataTemplate> 
 
        <DataTemplate x:Key="template2"> 
            <StackPanel Orientation="Horizontal"> 
                <Button Content="B1" Margin="5"/> 
                <Button Content="B2" Margin="5"/> 
            </StackPanel> 
        </DataTemplate> 
         
        <local:GridCellTemplateSelectorEXt x:Key="template"/> 
    </Window.Resources> 
 
<syncfusion:GridTemplateColumn MappingName="CustomerID"  
                               syncfusion:FocusManagerHelper.WantsKeyInput="True" 
                               CellTemplateSelector="{StaticResource template}"  
                               syncfusion:VisualContainer.WantsMouseInput="True"/> 
 
Please find sample for the same from the below link 
Sample Link: 
 
Also please refer to the below KB article to know more details on GridTemplateColumn 
KB Link: 
 
Please let us know, if you need any further assistance on this. 
 
Regards, 
Dinesh Babu Yadav. 
 


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

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

Live Chat Icon For mobile
Live Chat Icon