I have created a radcombobox inside my radgridview and bound some text to it which works fine, but I can't seem to get it to update the database for the selected row when I change the selection of the combo box?
My XAML:
<
telerik:GridViewDataColumn
Header
=
"Produktgruppe"
Width
=
"Auto"
MinWidth
=
"180"
IsReadOnly
=
"True"
>
<
telerik:GridViewDataColumn.CellStyle
>
<
Style
TargetType
=
"{x:Type telerik:GridViewCell}"
>
<
Setter
Property
=
"Template"
>
<
Setter.Value
>
<
ControlTemplate
TargetType
=
"{x:Type telerik:GridViewCell}"
>
<
telerik:RadComboBox
ItemsSource
=
"{Binding Source={StaticResource ViewModelProductGroups}, Path=ProductGroups}"
DisplayMemberPath
=
"Name"
IsEditable
=
"True"
IsReadOnly
=
"True"
SelectedIndex
=
"0"
EmptyText
=
"Vælg produktgruppe"
/>
</
ControlTemplate
>
</
Setter.Value
>
</
Setter
>
</
Style
>
</
telerik:GridViewDataColumn.CellStyle
>
</
telerik:GridViewDataColumn
>
My code-behind:
public Products()
{
InitializeComponent();
}
private void Page_Loaded(object sender, RoutedEventArgs e)
{
using (Context dbContext = new Context())
{
GvProducts.ItemsSource = dbContext.Product.Include(x => x.ProductGroup).ToList();
}
}
private void GvProducts_RowEditEnded(object sender, GridViewRowEditEndedEventArgs e)
{
if (e.NewData is Models.Product editedProduct)
{
using (Context dbContext = new Context())
{
dbContext.Entry(editedProduct).State = EntityState.Modified;
dbContext.SaveChanges();
}
}
}
My view model
sdf
public ObservableCollection<
Models.ProductGroup
> ProductGroups { get; set; }
public ViewModelProductGroups()
{
using (Context dbContext = new Context())
{
ProductGroups = new ObservableCollection<
Models.ProductGroup
>(dbContext.ProductGroup.ToList());
}
}
Any suggestions?