IEditableCollectionView.CanRemove Properti
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mendapatkan nilai yang menunjukkan apakah item dapat dihapus dari koleksi.
public:
property bool CanRemove { bool get(); };
public bool CanRemove { get; }
member this.CanRemove : bool
Public ReadOnly Property CanRemove As Boolean
Nilai Properti
true
jika item dapat dihapus dari koleksi; jika tidak, false
.
Contoh
Contoh berikut memanggil CanRemove untuk memeriksa apakah item dapat dihapus dari koleksi. Jika item dapat dihapus, contoh meminta pengguna untuk mengonfirmasi tindakan dan memanggil Remove jika pengguna mengklik Ya. Untuk seluruh sampel, lihat Mengubah Koleksi dengan Menggunakan Sampel IEditableCollectionView.
IEditableCollectionView editableCollectionView =
itemsControl.Items as IEditableCollectionView;
if (!editableCollectionView.CanRemove)
{
MessageBox.Show("You cannot remove items from the list.");
return;
}
if (MessageBox.Show("Are you sure you want to remove " + item.Description,
"Remove Item", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
editableCollectionView.Remove(itemsControl.SelectedItem);
}
Dim editableCollectionView As IEditableCollectionView = TryCast(itemsControl.Items, IEditableCollectionView)
If Not editableCollectionView.CanRemove Then
MessageBox.Show("You cannot remove items from the list.")
Return
End If
If MessageBox.Show("Are you sure you want to remove " & item.Description, "Remove Item", MessageBoxButton.YesNo) = MessageBoxResult.Yes Then
editableCollectionView.Remove(itemsControl.SelectedItem)
End If
Keterangan
CanRemove adalah false
jika koleksi yang mendasar bersifat baca-saja.