指定した Constraint をコレクションから削除します。
Overloads Public Sub Remove( _
ByVal constraint As Constraint _)
[C#]
public void Remove(Constraintconstraint);
[C++]
public: void Remove(Constraint* constraint);
[JScript]
public function Remove(
constraint : Constraint);
パラメータ
- constraint
削除する Constraint 。
例外
例外の種類 | 条件 |
---|---|
ArgumentNullException | 引数 constraint が null 参照 (Visual Basic では Nothing) です。 |
ArgumentException | この制約はコレクション内に存在しません。 |
解説
Remove メソッドを使用する前に、 Contains メソッドを使用して、ターゲットの Constraint がコレクション内に存在するかどうかを確認し、 CanRemove メソッドを使用して、 Constraint を削除できるかどうかを確認できます。
制約が正常に削除された場合は、 CollectionChanged イベントが発生します。
使用例
Private Sub RemoveConstraint(myTable As DataTable, myConstraint As Constraint)
Try
If myTable.Constraints.Contains(myConstraint.ConstraintName) Then
If myTable.Constraints.CanRemove(myConstraint) Then
myTable.Constraints.Remove(myConstraint)
End If
End If
Catch e As Exception
' Process exception and return.
Dim log As System.Diagnostics.EventLog = New System.Diagnostics.EventLog()
log.Source = "My Application"
log.WriteEntry(e.ToString())
Console.WriteLine("Exception of type {0} occurred.", e.GetType().ToString())
End Try
End Sub
[C#]
private void RemoveConstraint(DataTable myTable, Constraint myConstraint){
try{
if(myTable.Constraints.Contains(myConstraint.ConstraintName)) {
if(myTable.Constraints.CanRemove(myConstraint)) {
myTable.Constraints.Remove(myConstraint);
}
}
}
catch(Exception e) {
// Process exception and return.
System.Diagnostics.EventLog log = new System.Diagnostics.EventLog();
log.Source = "My Application";
log.WriteEntry(e.ToString());
Console.WriteLine("Exception of type {0} occurred.", e.GetType());
}
}
[C++]
private:
void RemoveConstraint(DataTable* myTable, Constraint* myConstraint){
try{
if(myTable->Constraints->Contains(myConstraint->ConstraintName)) {
if(myTable->Constraints->CanRemove(myConstraint)) {
myTable->Constraints->Remove(myConstraint);
}
}
}
catch(Exception* e) {
// Process exception and return.
System::Diagnostics::EventLog* log = new System::Diagnostics::EventLog();
log->Source = S"My Application";
log->WriteEntry(e->ToString());
Console::WriteLine(S"Exception of type {0} occurred.", e->GetType());
}
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET
参照
ConstraintCollection クラス | ConstraintCollection メンバ | System.Data 名前空間 | ConstraintCollection.Remove オーバーロードの一覧 | CanRemove | Contains | IndexOf