在Dictionary <int,list <dataset =“”>&gt; </int,>中捕获DataRowChanged事件

时间:2012-05-24 10:43:47

标签: c# winforms events dictionary datarow

我怎样才能抓住DataRowChanged中每个DataTable的{​​{1}}个事件?

2 个答案:

答案 0 :(得分:2)

    Dictionary<int, List<DataSet>> dict = new Dictionary<int, List<DataSet>>();
    foreach (var d in dict)
    {
        foreach (DataSet ds in d.Value)
        {
            foreach (DataTable dt in ds.Tables)
            {
                dt.RowChanged += new DataRowChangeEventHandler(dt_RowChanged);    
            }
        }
    }

答案 1 :(得分:1)

这样的东西
foreach(var kvp in dictionary){
kvp.Value.ForEach(dataset=>dataset.Tables.Cast<DataTable>().ToList().ForEach(table=>table.RowChanged+=yourhandler));
}

或更长的版本:

foreach(var kvp in dictionary)
{
    foreach(var dataset in kvp.Value)
    {
        foreach(var table in dataset.Tables)
        {  
            table.RowChanged+=yourhandler;
        }
    }
}