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

Hello, 

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

Regards,
Patrick

1 Reply

DY Deivaselvan Y Syncfusion Team 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 


Loader.
Up arrow icon