0

さて、私は次の問題を抱えています:

CurrentChangedイベントを発生させずに、バインディングソースから行を削除する必要があります。削除は問題なく機能しています。ただし、CurrentChangedイベントが即座に発生するため、CurrentChangedイベントに一致するコードが実行されます。それは問題につながります。.Delete()イベントを発生させずに同様の効果を達成する方法はありますか?

4

1 に答える 1

0

サブスクライバーが存在する場合、行を削除すると常にイベントが発生します。

イベントコードが制御下にある場合は、BindingSource_CurrentChangedイベントハンドラーでチェックするフラグを設定できます。

private void DeleteRow()
{
  this.justDeletedRow = true;
  this.bindingSource.DeleteRow(...);
}

protected void BindingSource_CurrentChanged(object sender ...)
{
  if (this.justDeletedRow)
  { 
     this.justDeletedRow = false;
     return;
  }

  // Process changes otherwise..
}

コードが制御下にない場合(たとえば、コンポーネントにバインドしている場合)、操作の実行中にハンドラーのバインドを解除できます。

private void DeleteRow()
{
  this.bindingSource.CurrentChanged -= this.component.BindingSource_CurrentChanged;
  this.bindingSource.DeleteRow(...);
  this.bindingSource.CurrentChanged += this.component.BindingSource_CurrentChanged;
}
于 2012-05-15T21:29:55.550 に答える