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.

How to Change column to be a button or a link (underline and blue) in c# code behind

Thread ID:

Created:

Updated:

Platform:

Replies:

125989 Sep 15,2016 06:26 PM Oct 20,2016 08:07 AM Xamarin.Forms 5
loading
Tags: SfDataGrid
Axel Gierbolini
Asked On September 15, 2016 06:26 PM

it is posible to display a button or a link in a cell so the user know that there is a event there not using XAML.

thanks

Divakar Subramaniam [Syncfusion]
Replied On September 16, 2016 05:14 AM

Hi Axel, 
 
Thanks for contacting Syncfusion Support.  
 
It is possible to display a button or a link in a cell in SfDataGrid using GridTemplateColumn. In GridTemplateColumn, you can able to load any custom views by using GridTemplateColumn.CellTemplate property and also you can able to load button in the header cell using GridTemplateColumn.HeaderTemplate property as in below code snippet. 
 
var column1 = new GridTemplateColumn() 
{ 
    MappingName = "CustomerID", 
    CellTemplate = new DataTemplate(typeof(ButtonClass)) //where ButtonClass is the custom view derived from Button. 
    HeaderTemplate = new DataTemplate(typeof(HeaderTemplate)) //where HeaderTemplate is the custom view derived from Button. 
 }; 
 
Please refer the below UG link to know more about GridTemplateColumn. 
 
 
We have prepared a sample by loading button in GridTemplateColumn for your reference and you can download the same from the below link. 
 
 
Also, you can able to load the buttons to the GridTemplateColumn at runtime. We have explained the same in the sample. 
 
Regards, 
Divakar.  
 


Robbie Philips
Replied On October 19, 2016 06:20 AM

How would you set the Clicked event property for the button? Only way I can find to do it is from within the ButtonClass but that's no good for me.

Thanks

Divakar Subramaniam [Syncfusion]
Replied On October 20, 2016 05:56 AM

Hi Robbie, 
 
 
Thanks for the update. 
 
 
You can set the clicked event property for the button in App.cs itself instead of setting in ButtonClass. Please refer the below code snippet to know how to achieve it. 
 
var column1 = new GridTemplateColumn() 
{ 
    MappingName = "CustomerID", 
    CellTemplate = new DataTemplate(() => 
    { 
        var button = new ButtonClass(); 
        button.Clicked += Button_Clicked; 
        return button; 
    }),          
    HeaderTemplate = new DataTemplate(typeof(HeaderTemplate)) 
}; 
 
 
Also, we have modified the sample based on your requirement and you can download the same from the below link. 
 
 
 
Regards, 
Divakar. 


Robbie Philips
Replied On October 20, 2016 06:20 AM

Thanks for that Divakar - seems I was just unsure of the syntax to initialise the object.

Divakar Subramaniam [Syncfusion]
Replied On October 20, 2016 08:07 AM

Hi Robbie, 
 
 
Thanks for the update. Please let us know if you need any other assistance from us. 
 
 
Regards, 
Divakar. 
 


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.

;