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: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to bind a ComboBox in a DetailView Template in C#

Thread ID:

Created:

Updated:

Platform:

Replies:

140773 Nov 6,2018 10:18 PM UTC Nov 8,2018 06:17 AM UTC WPF 1
loading
Tags: SfDataGrid
Patrick Feusi
Asked On November 6, 2018 10:33 PM UTC

Hello, 

is it possible to bind a ComboBoxAdv in DetailView Template of a SfDataGrid with C#?

Regards,
Patrick

Deivaselvan Y [Syncfusion]
Replied On November 8, 2018 06:17 AM UTC

Hi Patrick, 

Thank you for contacting Syncfusion support. 

We have analyzed your query “To bind ComboBoxAdv in DetailsViewTemplate with C#”. You can achieve your requirement by using the below code snippet 

public class SfDataGridBehavior: Behavior<SfDataGrid> 
{ 
        protected override void OnAttached() 
        { 
            TemplateViewDefinition templateViewDefinition = new TemplateViewDefinition(); 
            templateViewDefinition.RowTemplate = GetDataTemplate(); 
            this.AssociatedObject.DetailsViewDefinition.Add(templateViewDefinition); 
        } 
 
        private DataTemplate GetDataTemplate() 
        { 
            FrameworkElementFactory comboBoxAdv = new FrameworkElementFactory(typeof(ComboBoxAdv)); 
            comboBoxAdv.SetValue(ComboBoxAdv.HorizontalAlignmentProperty, HorizontalAlignment.Center); 
            comboBoxAdv.SetValue(ComboBoxAdv.VerticalAlignmentProperty, VerticalAlignment.Center); 
            comboBoxAdv.SetValue(ComboBoxAdv.SelectedValueProperty, "ProductName"); 
            comboBoxAdv.SetValue(ComboBoxAdv.DisplayMemberPathProperty, "ProductName"); 
           comboBoxAdv.SetValue(ComboBoxAdv.WidthProperty, 200d); 
             
            Binding binding = new Binding(); 
            binding.Path = new PropertyPath("DataContext.OrderList"); 
            binding.ElementName = this.AssociatedObject.Name; 
            comboBoxAdv.SetBinding(ComboBoxAdv.ItemsSourceProperty, binding);  
 
            var dataTemplate = new DataTemplate() { VisualTree = comboBoxAdv }; 
            return dataTemplate; 
        } 
} 

Please find sample for the same from below link and let us know if this helps you. 

Regards,
Deivaselvan 


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

;