0

我有带有更改/删除事件的数据集:

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;
}

boolfirstTime在开始时设置为 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 带有 i++ 参数):68

产品数量:35,操作:提交,我在这里多少次(i 带有 i++ 参数):69

4

0 回答 0