항목이 BindingList에 추가되면 ListChange 이벤트가 알려서 이에 따라 대응할 수 있습니다. 항목 목록에서 제거 때 항목이 더 이상 목록에 그대로BindingList.AboutToRemove 이벤트 찾기
그러나 ListChange 이벤트는, 너무 늦게 온다. 제거 방법을 알아 내려면 전에이 제거 되었습니까?
첨부 된 이벤트 처리기를 제거 할 수 있도록 개체를 식별해야합니다.
항목이 BindingList에 추가되면 ListChange 이벤트가 알려서 이에 따라 대응할 수 있습니다. 항목 목록에서 제거 때 항목이 더 이상 목록에 그대로BindingList.AboutToRemove 이벤트 찾기
그러나 ListChange 이벤트는, 너무 늦게 온다. 제거 방법을 알아 내려면 전에이 제거 되었습니까?
첨부 된 이벤트 처리기를 제거 할 수 있도록 개체를 식별해야합니다.
BindingList<T>
의 현재 구현은이를 지원하지 않는 것으로 보입니다. 최선의 방법은 제거 이벤트가있는 BindingList의 구현을 직접 작성하는 것입니다.
public class MyBindingList<T> : BindingList<T>
{
public event ListChangedEventHandler Removing;
protected void OnRemoving(ListChangedEventArgs e)
{
if(Removing != null)
{
Removing(this, e);
}
}
protected override void RemoveItem(int index)
{
if(index > -1 && index < this.Count)
{
OnRemoving(new ListChangedEventArgs(ListChangedType.ItemDeleted, index));
base.RemoveItem(index);
}
}
}
Rex의 C# 코드의 VB 암시입니다.
Imports System.ComponentModel
Public Class MyBindingList
Inherits BindingList(Of T)
Public Event Removing As ListChangedEventHandler
Protected Overrides Sub RemoveItem(ByVal index As Integer)
If index > -1 AndAlso index < Me.Count Then
RaiseEvent Removing(Me, New ListChangedEventArgs(ListChangedType.ItemDeleted, index))
End If
MyBase.RemoveItem(index)
End Sub
End Class
감사합니다. VB 응용 프로그램에 C# 코드를 적용 할 수 있었지만 잘 작동합니다. – Bill