Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fire DataTableNewRowEvent after Rows.Add

Now I have

var row = container.Tables[name].NewRow();
row[0] = time;
row[1] = val;
container.Tables[name].Rows.Add(row);

Of course event DataTableNewRowEvent is fired in first line. But I need fire them after last line, I mean after adding new row to RowsCollection. How to make it? I need it to get actual data in DataTable at the moment of firing DataTableNewRowEvent

I think about:

//to insert proper data
var row = container.Tables[name].NewRow();
row[0] = time;
row[1] = val;
container.Tables[name].Rows.Add(row);
//to fire event
container.Tables[name].Rows.Remove(container.Tables[name].NewRow());

but probably it's not best solution.

like image 836
Saint Avatar asked Dec 21 '22 21:12

Saint


1 Answers

I think you better handle the RowChanged event on DataTable, you'll get a parameter of type DataRowChangeEventArgs that has a DataRowAction property that let's you know the change that actually took place on the row, Add being one of the possible values.

Your handler would look like this

protected void DataTable_RowChanged(object sender, DataRowChangeEventArgs e)
{
    if (e.Action == DataRowAction.Add)
    {
        // Do something with e.Row which is already populated
    }
}
like image 158
Amanda Tarafa Mas Avatar answered Dec 23 '22 11:12

Amanda Tarafa Mas