Hello, I think I can help you, I have this code for a database in sqlServer and I have a data source with a DataSet for my database
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using TestDeDataGrid.TestDSTableAdapters; namespace TestDeDataGrid { public partial class MainWindow : Window {
With this trick, column C is calculated automatically after I have a value in columns A and B, for example, if I put 10 in columna A and 5 in column B then I just press Tab to go to column C, and the value 2 appears automatically there is no need to press another line or press the enter key.
Column C is a computed column with an expression (ColumnaA / ColumnaB) and of type System.Decimal.
And there is my xaml code:
<DataGrid Name="TablaTestGrid" Grid.Row="1" AutoGenerateColumns="False" CurrentCellChanged="TablaTestGrid_CurrentCellChanged"> <DataGrid.Columns> <DataGridTextColumn Header="ID" Binding="{Binding Path=IdTablaTest}" IsReadOnly="True"></DataGridTextColumn> <DataGridTextColumn Header="Col A" Binding="{Binding Path=ColumnaA}"></DataGridTextColumn> <DataGridTextColumn Header="Col B" Binding="{Binding Path=ColumnaB}"></DataGridTextColumn> <DataGridTextColumn Header="A/B" Binding="{Binding Path=ColumnaC}" IsReadOnly="True" ></DataGridTextColumn> <DataGridTextColumn Header="TestOnly"></DataGridTextColumn> </DataGrid.Columns> </DataGrid>
source share