Category / Section
How to bind SelectedValue for the SfComboBox within the SfDataGrid?
1 min read
In SfComboBox, you can bind the SelectedValue property of the SfComboBox. When SfComboBox is used as a template for the SfDataGrid column, set the SelectedValue in a separate SfComboBox. You can also set the SelectedValue for each SfComboBox in the SfDataGrid in a loaded event. This can be achieved in the following code.
XAML
<syncfusion:GridTemplateColumn MappingName="ShipCountry"> <syncfusion:GridTemplateColumn.CellTemplate> <DataTemplate> <editors:SfComboBox x:Name="Combo" Loaded="Combo_Loaded"/> </DataTemplate> </syncfusion:GridTemplateColumn.CellTemplate> </syncfusion:GridTemplateColumn>
C#
private void Combo_Loaded(object sender, RoutedEventArgs e) { SfComboBox combobox = sender as SfComboBox; if(combobox!=null) { combobox.ItemsSource = new ShipCountries(); combobox.SetBinding(SfComboBox.SelectedValueProperty, sfdatagrid.Columns["ShipCountry"].DisplayBinding); } }
Figure 1: SelectedValues are binded to the SfComboBox
Figure 2: SfComboBox dropdown is opened