I display dataGrid in WPF and entity framework, column 2 has a price per unit column 3 has the quantity (column 4 has the discount), I want column 5 will be the summary. My question is how I can capture the third column and calculate the change to the total column
Here is the code How do I display the data
<DataGrid.Columns>
<DataGridComboBoxColumn x:Name="ddd" Header="Expenses" Width="*" SelectedValueBinding="{Binding Path=ExpensesId}" DisplayMemberPath="ExpensesName" SelectedValuePath="ExpensesTypeId"/>
<DataGridTextColumn Header="price" Width="*" Binding="{Binding Path=Expenses.PricePorEach}"/>
<DataGridTextColumn Header="quantity" Width="50" Binding="{Binding Path=Quantity}"/>
<DataGridTextColumn Header="discount" Width="*" Binding="{Binding Path=Discount}"/>
<DataGridTextColumn Header="Total" Width="*" Binding="{Binding Path=Total}"/>
</DataGrid.Columns>
</DataGrid>
ContractorEntities ce = new ContractorEntities();
public MainWindow()
{
InitializeComponent();
BindData();
}
private void BindData()
{
var dataSource = new ObservableCollection<Jobs>(ce.Jobs);
dataSource.CollectionChanged += CollectionChanged;
dg.ItemsSource = dataSource;
dg.DataContext = dataSource;
}
private void CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
if (e.Action == NotifyCollectionChangedAction.Add)
foreach (Jobs job in e.NewItems)
ce.Jobs.Add(job);
else if (e.Action == NotifyCollectionChangedAction.Remove)
foreach (Jobs jobin e.OldItems)
ce.Jobs.Remove(job);
}
private void saveButton_Click(object sender, RoutedEventArgs e)
{
ce.SaveChanges();
}
[NotMapped]
public decimal? Total
{
get
{
return (Price * Quantity) - Discount;
}
set { }
}
public void OnDiscountChanged()
{
base.OnPropertyChanged("Total");//This line is not known
}
public void OnPriceChanged()
{
base.OnPropertyChanged("Total");//This line is not known
}
public void OnQuantityChanged()
{
base.OnPropertyChanged("Total");//This line is not known
}
}
I tried several ways, but no results
Thanks in advance for help