Sai*_*int 2 c# datatable events newrow winforms
我现在有
var row = container.Tables[name].NewRow();
row[0] = time;
row[1] = val;
container.Tables[name].Rows.Add(row);
Run Code Online (Sandbox Code Playgroud)
当然事件DataTableNewRowEvent在第一行被触发.但我需要在最后一行之后解雇它们,我的意思是在添加新行之后RowsCollection.怎么做?我需要它来在DataTable射击时获取实际数据DataTableNewRowEvent
我想想:
//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());
Run Code Online (Sandbox Code Playgroud)
但可能这不是最好的解决方案.
我认为你最好处理这个RowChanged事件DataTable,你会得到一个类型的参数,DataRowChangeEventArgs它有一个DataRowAction属性,让你知道实际发生在行上的变化,是Add可能的值之一.
你的处理程序看起来像这样
protected void DataTable_RowChanged(object sender, DataRowChangeEventArgs e)
{
if (e.Action == DataRowAction.Add)
{
// Do something with e.Row which is already populated
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4986 次 |
| 最近记录: |