DataSet事件引发太多次

时间:2013-11-04 13:57:27

标签: c# events dataset

我有带有更改/删除事件的DataSet:

adapterNB = new DocumentProductsNBAdapter();
adapterNB.Connection = conn;
adapterNB.ClearBeforeFill = true;
adapterNB.Adapter.AcceptChangesDuringUpdate = true;
adapterNB.Adapter.AcceptChangesDuringFill = true;

adapterNB.Fill(ds.DocumentProductsNB, documentID);
productsDG.DataContext = null;
productsDG.DataContext = ds.DocumentProductsNB.DefaultView;
productsDG.ItemsSource = ds.DocumentProductsNB.DefaultView; 
if (!firstTime)
{
   ds.DocumentProductsNB.DocumentProductsNBRowChanged +=
      new WarehousesDataSet.DocumentProductsNBRowChangeEventHandler(updateNB);
   ds.DocumentProductsNB.DocumentProductsNBRowDeleted +=
      new WarehousesDataSet.DocumentProductsNBRowChangeEventHandler(updateNB); 
   firstTime = true;
}

bool firstTime在开头(进入窗口时)设置为false。

问题是,当我在事件中放置断点时:

void updateNB(object sender, WarehousesDataSet.DocumentProductsNBRowChangeEvent e)
{
   //(....) breakpoint here
}

事件恰好提升2 x GridView.Items.Count次。因此,对于10个网格产品,活动提高了20倍。有谁知道为什么?我确定我没有“ds”的任何其他+ =事件。

谢谢!

我把这些行放在updateNB事件中:

 Console.WriteLine("Products count: " + productsDG.Items.Count + ", Action: " + e.Action + ", how many times I was here (i with i++ parameter): " + iI);
                iI++;

结果:

  

(...)

     

产品数量:35,动作:添加,我在这里的次数(我用i ++   参数):68

     

产品数量:35,行动:承诺,我在这里多少次(我有   i ++参数):69

0 个答案:

没有答案