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.

SfDataGrid-Column with Buttons

Thread ID:

Created:

Updated:

Platform:

Replies:

131609 Jul 19,2017 08:02 AM Jul 20,2017 11:56 PM WPF 1
loading
Tags: SfDataGrid
Harald Betzler
Asked On July 19, 2017 08:02 AM

Hi,

I've a list of data items with two properties (ItemName (string) and ItemFlag (boolean)). I want to have a SfDataGrid with two columns. 

A text column displaying the ItemName and a button column displaying a button (bound to a viewmodel command) if ItemFlag=true or displaying nothing (or a disabled button) if ItemFlag=false.

I think I'll need a DataTemplateSelector but in my trials the overridden SelectTemplate method was never called.

Can you help me?

Regards
Harald

Muthukumar Kalyanasundaram [Syncfusion]
Replied On July 20, 2017 11:47 PM

Hi Harald, 
 
Thank you for contacting Syncfusion support. 
 
We have checked your query. You can pass the row information as a parameter to the command in ViewModel when clicking a button in TemplateColumn by passing the CommandParameter like the below code example,  
 
Code Snippet: 
 
<syncfusion:SfDataGrid.Columns>                
    <syncfusion:GridTextColumn MappingName="Name" /> 
    <syncfusion:GridTemplateColumn MappingName="City" syncfusion:FocusManagerHelper.WantsKeyInput="True"> 
        <syncfusion:GridTemplateColumn.CellTemplate> 
            <DataTemplate> 
                <Button  Content="Click" syncfusion:FocusManagerHelper.FocusedElement="True"   
Command="{Binding Path=DataContext.RowDataCommand,ElementName=sfGrid}" CommandParameter="{Binding}"/> 
            </DataTemplate> 
        </syncfusion:GridTemplateColumn.CellTemplate> 
    </syncfusion:GridTemplateColumn> 
 
</syncfusion:SfDataGrid.Columns> 
 
 
For your reference, we have attached sample and KB link. Could you please refer to it. 
 
Please let us know if you have any query. 
 
Regards, 
Muthukumar K 


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.

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.

;