IEditableCollectionView インターフェイス

定義

コレクションに編集機能を提供するために CollectionView に実装されるメソッドとプロパティを定義します。

public interface class IEditableCollectionView
public interface IEditableCollectionView
type IEditableCollectionView = interface
Public Interface IEditableCollectionView
派生

次の例では、定義されているメソッドを使用してコレクションに項目を追加する方法を IEditableCollectionView示します。 このアプリケーションは、販売対象のアイテムの一覧を表示し、ユーザーに項目の追加、編集、または削除のオプションを提供します。 ユーザーが項目を追加または編集すると、フォームはユーザーに新しい項目の入力を求めます。 ユーザーがフォームを送信すると、アイテムはコレクションにコミットされます。 ユーザーがフォームを取り消すと、アイテムは破棄されます。 サンプル全体については、「 IEditableCollectionView サンプルを使用したコレクションの変更」を参照してください。

IEditableCollectionView editableCollectionView = 
    itemsControl.Items as IEditableCollectionView; 

if (!editableCollectionView.CanAddNew)
{
    MessageBox.Show("You cannot add items to the list.");
    return;
}

// Create a window that prompts the user to enter a new
// item to sell.
ChangeItemWindow win = new ChangeItemWindow();

//Create a new item to be added to the collection.
win.DataContext = editableCollectionView.AddNew();

// If the user submits the new item, commit the new
// object to the collection.  If the user cancels 
// adding the new item, discard the new item.
if ((bool)win.ShowDialog())
{
    editableCollectionView.CommitNew();
}
else
{
    editableCollectionView.CancelNew();
}
Dim editableCollectionView As IEditableCollectionView = TryCast(itemsControl.Items, IEditableCollectionView)

If Not editableCollectionView.CanAddNew Then
    MessageBox.Show("You cannot add items to the list.")
    Return
End If

' Create a window that prompts the user to enter a new
' item to sell.
Dim win As New ChangeItemWindow()

'Create a new item to be added to the collection.
win.DataContext = editableCollectionView.AddNew()

' If the user submits the new item, commit the new
' object to the collection.  If the user cancels 
' adding the new item, discard the new item.
If CBool(win.ShowDialog()) Then
    editableCollectionView.CommitNew()
Else
    editableCollectionView.CancelNew()
End If

注釈

コレクション ビューでインターフェイスが IEditableCollectionView 実装されている場合は、コレクションの型に関係なく、公開するメソッドとプロパティ IEditableCollectionView を使用して、基になるコレクションを直接変更できます。

ItemCollectionは、BindingListCollectionViewListCollectionView継承するWindows Presentation Foundation (WPF) に付属するCollectionView型です。 これらの型も実装 IEditableCollectionViewされているため、これらの型のいずれかを使用するコレクションを編集できます。 ItemCollection特に、プロパティItemCollectionItemsControl.Items .

プロパティ

CanAddNew

新しい項目をコレクションに追加できるかどうかを示す値を取得します。

CanCancelEdit

コレクション ビューが保留中の変更を破棄して、編集されたオブジェクトの元の値を復元できるかどうかを示す値を取得します。

CanRemove

コレクションから項目を削除できるかどうかを示す値を取得します。

CurrentAddItem

現在の追加トランザクション処理中に追加される項目を取得します。

CurrentEditItem

編集されているコレクション内の項目を取得します。

IsAddingNew

追加トランザクションが実行中かどうかを示す値を取得します。

IsEditingItem

編集トランザクションが実行中かどうかを示す値を取得します。

NewItemPlaceholderPosition

コレクション ビューにある新しい項目のプレースホルダーの位置を取得または設定します。

メソッド

AddNew()

新しい項目をコレクションに追加します。

CancelEdit()

編集トランザクションを終了し、可能な場合は、項目の元の値を復元します。

CancelNew()

追加トランザクションを終了し、保留中の新しい項目を破棄します。

CommitEdit()

編集トランザクションを終了し、保留中の変更を保存します。

CommitNew()

追加トランザクションを終了し、保留中の新しい項目を保存します。

EditItem(Object)

指定した項目の編集トランザクションを開始します。

Remove(Object)

指定した項目をコレクションから削除します。

RemoveAt(Int32)

コレクション内の指定した位置にある項目を削除します。

適用対象