I'm working on a project where I need to select a value from a list of objects and then update the other values displayed in the same row based on the selection that is made, with the properties of the selected object. I bind the list in my VM (using Prism) to the DataGridComboBoxColumn and is working fine, but there's no event SelectionChanged that I can bind to. I'm actually using Telerik's RadDataGrid, my code is:
<telerikGrid:RadDataGrid x:Name="ArticlesDataGrid" Margin="0,8,0,0"
ItemsSource="{x:Bind MasterMenuItem.Articles, Mode=TwoWay}" UserEditMode="Inline" UserGroupMode="Disabled" AutoGenerateColumns="False">
<telerikGrid:RadDataGrid.Columns>
<telerikGrid:DataGridComboBoxColumn PropertyName="Code" ItemsSource="{x:Bind ViewModel.Articles}" DisplayMemberPath="Code" SelectedValuePath="Code" />
<telerikGrid:DataGridComboBoxColumn PropertyName="Description" ItemsSource="{x:Bind ViewModel.Articles}" DisplayMemberPath="Description" SelectedValuePath="Description" />
<telerikGrid:DataGridTextColumn PropertyName="MeasureUnit.Description" CanUserEdit="False" />
<telerikGrid:DataGridTextColumn PropertyName="VatCode.Description" CanUserEdit="False"/>
<telerikGrid:DataGridTextColumn PropertyName="Price" CanUserEdit="False"/>
<telerikGrid:DataGridTextColumn PropertyName="Quantity" />
<telerikGrid:DataGridTextColumn PropertyName="Total" CanUserEdit="False" />
</telerikGrid:RadDataGrid.Columns>
</telerikGrid:RadDataGrid>
I need that when the columns Description or Code are changed, I can update the content in the others columns of the same row. Can someone point me in the right direction?
Thank you!
Instead of handling an event, you could implement your logic in the setters of the Description
and Code
properties, e.g.:
private string _description;
public string Description
{
get { return _description; }
set
{
SetProperty(ref _description, value);
//your "selection changed" logic goes here...
}
}
As @Xavier Xie suggests, the class where the Description
, Code
, Price
, Quantity
, etc. properties are defined should implement the INotifyPropertyChanged
interface and raise change notifications for the view to be refreshed automatically. Please refer to MSDN for more information about this.
Since you are using Prism, you could inherit from Prism.Mvvm.BindableBase
and call the SetProperty<T>
method to both set and raise a change notification for a property.