バージョン

RecordsDeletingEventArgs クラス

ルーティング イベント Infragistics.Windows.DataPresenter.DataPresenterBase.RecordsDeleting のイベント引数
シンタックス
'宣言
 
Public Class RecordsDeletingEventArgs 
   Inherits Infragistics.Windows.Controls.Events.CancelableRoutedEventArgs
public class RecordsDeletingEventArgs : Infragistics.Windows.Controls.Events.CancelableRoutedEventArgs 
使用例
using Infragistics.Windows;
using Infragistics.Windows.DataPresenter;
using System.Collections;
using System.ComponentModel;
using System.Collections.Specialized;

	private void grid_RecordsDeleting(object sender, Infragistics.Windows.DataPresenter.Events.RecordsDeletingEventArgs e)
	{
		// during the RecordsDeleting the records have not been deleted. in order to 
		// allow the end user to recreate those records, you must provide a custom
		// undeletestrategy that can store the data needed before the delete and 
		// perform the undeletion when requested (when the user attempts to perform
		// an undo). this strategy is a basic one that will reinsert the original
		// item into the containing list so this would work with ibindinglist<t> and 
		// observablecollection<t> type classes. this will not work with datatable/
		// dataset. for more examples please refer to the advanced undo sample in 
		// the feature browser sample
		e.UndeleteStrategy = new ListUndeleteStrategy(e.Records);
	}

	private void grid_Initialized(object sender, EventArgs e)
	{
		DataPresenterBase dp = sender as DataPresenterBase;
		var list = new BindingList<Employee>();
		list.Add(new Employee( "John", new DateTime(2008, 1, 1) ));
		list.Add(new Employee( "Mary", new DateTime(2007, 8, 5) ));
		list.Add(new Employee( "Paul", new DateTime(2003, 3, 14) ));
		dp.DataSource = list;
	}

	#region ListUndeleteStrategy
	// This sample strategy assumes that the objects that were removed from the collection 
	// can be reinserted into the collection and therefore this does not work with things 
	// like dataview, datatable and dataset. you should refer to the advanced undo sample 
	// in the samples browser for more examples
	public class ListUndeleteStrategy : UndeleteRecordsStrategy
	{
		public ListUndeleteStrategy(IList<Record> records)
		{
		}

		public override bool CanUndelete(IList<UndeleteRecordsStrategy.RecordInfo> oldRecords)
		{
			return true;
		}

		public override IDictionary<RecordInfo, object> Undelete(IList<RecordInfo> oldRecords)
		{
			Dictionary<RecordInfo, object> oldToNewMapping = new Dictionary<RecordInfo, object>();

			RecordInfo[] records = oldRecords.ToArray();
			Comparison<RecordInfo> comparison = delegate(RecordInfo item1, RecordInfo item2)
			{
				return item1.DataItemIndex.CompareTo(item2.DataItemIndex);
			};

			// sort by the original index to ensure we get them in the original order
			Utilities.SortMergeGeneric(records, Utilities.CreateComparer(comparison));

			foreach (RecordInfo record in records)
			{
				RecordManager rm = record.RecordManager;
				IList list = rm.SourceItems as IList;

				if (list == null)
					continue;

				int newIndex = Math.Min(list.Count, record.DataItemIndex);
				object newDataItem = record.DataItem;

				list.Insert(newIndex, newDataItem);

				// since we're reusing the same object the old and new will be the same
				oldToNewMapping[record] = newDataItem;
			}

			return oldToNewMapping;
		}
	}
	#endregion //ListUndeleteStrategy

	#region Employee
	public class Employee
	{
		private string _name;
		private DateTime _hireDate;

		public Employee(string name, DateTime hireDate)
		{
			_name = name;
			_hireDate = hireDate;
		}

		public string Name
		{
			get { return _name; }
		}

		public DateTime HireDate
		{
			get { return _hireDate; }
		}
	} 
	#endregion //Employee
xmlns:igDP="http://infragistics.com/DataPresenter"

<igDP:XamDataGrid xmlns:igDP="http://infragistics.com/DataPresenter"
    
x:Name="grid" 
    
BindToSampleData="True"
    
IsUndoEnabled="True"
    
Initialized="grid_Initialized"
    
RecordsDeleting="grid_RecordsDeleting">
</igDP:XamDataGrid>
Imports Infragistics.Windows
Imports Infragistics.Windows.DataPresenter
Imports Infragistics.Windows.DataPresenter.UndeleteRecordsStrategy
Imports System.Globalization
Imports System.ComponentModel

    Private Sub grid_RecordsDeleting(ByVal sender As System.Object, ByVal e As Infragistics.Windows.DataPresenter.Events.RecordsDeletingEventArgs)
        ' during the RecordsDeleting the records have not been deleted. in order to 
        ' allow the end user to recreate those records, you must provide a custom
        ' undeletestrategy that can store the data needed before the delete and 
        ' perform the undeletion when requested (when the user attempts to perform
        ' an undo). this strategy is a basic one that will reinsert the original
        ' item into the containing list so this would work with ibindinglist<t> and 
        ' observablecollection<t> type classes. this will not work with datatable/
        ' dataset. for more examples please refer to the advanced undo sample in 
        ' the feature browser sample
        e.UndeleteStrategy = New ListUndeleteStrategy(e.Records)
    End Sub

    Private Sub grid_Initialized(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim dp As DataPresenterBase = DirectCast(sender, DataPresenterBase)
        Dim list As BindingList(Of Employee) = New BindingList(Of Employee)()
        list.Add(New Employee("John", New DateTime(2008, 1, 1)))
        list.Add(New Employee("Mary", New DateTime(2007, 8, 5)))
        list.Add(New Employee("Paul", New DateTime(2003, 3, 14)))
        dp.DataSource = list
    End Sub


#Region "ListUndeleteStrategy"
    ' This sample strategy assumes that the objects that were removed from the collection 
    ' can be reinserted into the collection and therefore this does not work with things 
    ' like dataview, datatable and dataset. you should refer to the advanced undo sample 
    ' in the samples browser for more examples
    Public Class ListUndeleteStrategy
        Inherits UndeleteRecordsStrategy
        Public Sub New(ByVal records As IList(Of Record))
        End Sub

        Public Overrides Function CanUndelete(ByVal oldRecords As IList(Of UndeleteRecordsStrategy.RecordInfo)) As Boolean
            Return True
        End Function

        Public Overrides Function Undelete(ByVal oldRecords As IList(Of RecordInfo)) As IDictionary(Of RecordInfo, Object)
            Dim oldToNewMapping As New Dictionary(Of RecordInfo, Object)
            Dim records As RecordInfo() = oldRecords.ToArray()

            Dim comparison As Comparison(Of RecordInfo) = Function(item1 As RecordInfo, item2 As RecordInfo) item1.DataItemIndex.CompareTo(item2.DataItemIndex)

            ' sort by the original index to ensure we get them in the original order
            Utilities.SortMergeGeneric(records, Utilities.CreateComparer(comparison))

            For Each record As RecordInfo In records
                Dim rm As RecordManager = record.RecordManager
                Dim list As IList = TryCast(rm.SourceItems, IList)

                If list Is Nothing Then Continue For

                Dim newIndex As Integer = Math.Min(list.Count, record.DataItemIndex)
                Dim newDataItem As Object = record.DataItem

                list.Insert(newIndex, newDataItem)

                ' since we're reusing the same object the old and new will be the same
                oldToNewMapping(record) = newDataItem
            Next record

            Return oldToNewMapping
        End Function
    End Class
#End Region 'ListUndeleteStrategy

#Region "Employee"
    Public Class Employee
        Private _name As String
        Private _hireDate As DateTime

        Public Sub New(ByVal name As String, ByVal hireDate As DateTime)
            _name = name
            _hireDate = hireDate
        End Sub

        Public ReadOnly Property Name() As String
            Get
                Return _name
            End Get
        End Property

        Public ReadOnly Property HireDate() As DateTime
            Get
                Return _hireDate
            End Get
        End Property
    End Class
#End Region 'Employee
参照