Вопрос по events, c#, wpf – Как вызвать событие при изменении DataGrid.ItemsSource

28

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

dataGrid.ItemsSource = table.DefaultView;

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

CollectionView myCollectionView = (CollectionView)CollectionViewSource.GetDefaultView(myGrid.Items);
((INotifyCollectionChanged)myCollectionView).CollectionChanged += new NotifyCollectionChangedEventHandler(DataGrid_CollectionChanged); 

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded Limey

Ваш Ответ

3   ответа
56

ItemsSourceError: User Rate Limit Exceeded

Error: User Rate Limit ExceededWindow.LoadedError: User Rate Limit Exceeded

var dpd = DependencyPropertyDescriptor.FromProperty(ItemsControl.ItemsSourceProperty, typeof(DataGrid));
if (dpd != null)
{
    dpd.AddValueChanged(myGrid, ThisIsCalledWhenPropertyIsChanged);
}

Error: User Rate Limit Exceeded

private void ThisIsCalledWhenPropertyIsChanged(object sender, EventArgs e)
{
}

Error: User Rate Limit ExceededItemsSourceError: User Rate Limit ExceededThisIsCalledWhenPropertyIsChangedError: User Rate Limit Exceeded

Error: User Rate Limit ExceededanyError: User Rate Limit Exceeded

Error: User Rate Limit Exceeded
Error: User Rate Limit ExceededmyGridError: User Rate Limit ExceededDependencyPropertyDescriptorError: User Rate Limit ExceededSee this question for details
Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
11

public class MyDataGrid : DataGrid
{
    protected override void OnItemsSourceChanged(
                                    IEnumerable oldValue, IEnumerable newValue)
    {
        base.OnItemsSourceChanged(oldValue, newValue);

        // do something here?
    }

    protected override void OnItemsChanged(NotifyCollectionChangedEventArgs e)
    {
        base.OnItemsChanged(e);

        switch (e.Action)
        {
            case NotifyCollectionChangedAction.Add:
                break;
            case NotifyCollectionChangedAction.Remove:
                break;
            case NotifyCollectionChangedAction.Replace:
                break;
            case NotifyCollectionChangedAction.Move:
                break;
            case NotifyCollectionChangedAction.Reset:
                break;
            default:
                throw new ArgumentOutOfRangeException();
        }
    }
}
-2

InitializingNewItemAddingNewItem

InitializingNewItem

Похожие вопросы