Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DataTable RowChanged how to get previous Row value? [closed]

I have a DataTable. When change in row happens I need to get this row and it's previous value(DataRow). How can I get it?

like image 657
Dork Avatar asked Mar 14 '13 17:03

Dork


People also ask

How to get the previous row's value in a query?

The answer set doesn't match your query, it will include 'C' rows, too. ROWS between UNBOUNDED PRECEDING and CURRENT ROW is a group sum. You need ROWS between 1 PRECEDING and 1 PRECEDNG and an ORDER BY to get the previous row's value.

How many rows and columns are there in Table 1?

Table 1 shows that our exemplifying data.table consists of five rows and five columns. This example explains how to get the values from one row before when doing calculations with a data.table.

How to get the previous row's value in a group sum?

ROWS between UNBOUNDED PRECEDING and CURRENT ROW is a group sum. You need ROWS between 1 PRECEDING and 1 PRECEDNG and an ORDER BY to get the previous row's value. Better switch to LAG or LAST_VALUE, which is simpler and allows dealing with additional rows between the 'A15' and the previous 'C' row:

How to deal with multiple rows between A15 and C Row?

Better switch to LAG or LAST_VALUE, which is simpler and allows dealing with additional rows between the 'A15' and the previous 'C' row:


1 Answers

You should subscribe to the ColumnChanged event, that way you can see the previous and current values.

Example:

//code to wire up the handler
custTable.ColumnChanged += new DataColumnChangeEventHandler(Column_Changed);

//code for the event
private static void Column_Changed(object sender, DataColumnChangeEventArgs e )
{
    Console.WriteLine("Column_Changed Event: name={0}; Column={1}; original name={2}", 
        e.Row["name"], e.Column.ColumnName, e.Row["name", DataRowVersion.Original]);
}
like image 171
mattytommo Avatar answered Nov 14 '22 23:11

mattytommo