DataView.RowStateFilter プロパティ
DataView 内で使用する行状態フィルタを取得または設定します。
Public Property RowStateFilter As DataViewRowState
[C#]
public DataViewRowState RowStateFilter {get; set;}
[C++]
public: __property DataViewRowState get_RowStateFilter();public: __property void set_RowStateFilter(DataViewRowState);
[JScript]
public function get RowStateFilter() : DataViewRowState;public function set RowStateFilter(DataViewRowState);
プロパティ値
DataViewRowState 値の 1 つ。
解説
Delete メソッドを使用して削除された行だけ、その行の RowStateFilter 値が Deleted に設定されます。同様に、 AddNew メソッドを使用して追加された行は、そのプロパティが Added に設定されます。
メモ DataRowCollection クラスの Remove メソッドを使用すると、行は Deleted としてマークされません。このメソッドではなく Delete メソッドを使用して、 DataView に行を表示できるようにしてください。
RowStateFilter が ModifiedCurrent または CurrentRows に設定されているときは、新しい行も表示されます。
RowStateFilter が ModifiedOriginal または OriginalRows に設定されているときは、削除された行も表示されます。
使用例
[Visual Basic, C#, C++] 1 つの列で DataTable を作成し、データを変更し、 DataView の RowStateFilter を設定して、 DataViewRowState に応じて異なる行セットを表示する例を次に示します。
Private Sub DemonstrateRowState()
Dim i As Integer
' Create a DataTable with one column.
Dim myTable As New DataTable("myTable")
Dim myColumn As New DataColumn("myColumn")
myTable.Columns.Add(myColumn)
' Add ten rows.
Dim myRow As DataRow
For i = 0 To 9
myRow = myTable.NewRow()
myRow("myColumn") = "item " + i.ToString()
myTable.Rows.Add(myRow)
Next i
myTable.AcceptChanges()
' Create a DataView with the table.
Dim myView As New DataView(myTable)
' Change one row's value:
myTable.Rows(1)("myColumn") = "Hello"
' Add one row:
myRow = myTable.NewRow()
myRow("myColumn") = "World"
myTable.Rows.Add(myRow)
' Set the RowStateFilter to display only Added and modified rows.
myView.RowStateFilter = _
DataViewRowState.Added Or DataViewRowState.ModifiedCurrent
' Print those rows. Output = "Hello" "World";
PrintView(myView, "ModifiedCurrent and Added")
' Set filter to display on originals of modified rows.
myView.RowStateFilter = DataViewRowState.ModifiedOriginal
PrintView(myView, "ModifiedOriginal")
' Delete three rows.
myTable.Rows(1).Delete()
myTable.Rows(2).Delete()
myTable.Rows(3).Delete()
' Set the RowStateFilter to display only Added and modified rows.
myView.RowStateFilter = DataViewRowState.Deleted
PrintView(myView, "Deleted")
'Set filter to display only current.
myView.RowStateFilter = DataViewRowState.CurrentRows
PrintView(myView, "Current")
' Set filter to display only unchanged rows.
myView.RowStateFilter = DataViewRowState.Unchanged
PrintView(myView, "Unchanged")
' Set filter to display only original rows.
myView.RowStateFilter = DataViewRowState.OriginalRows
PrintView(myView, "OriginalRows")
End Sub
Private Sub PrintView(dv As DataView, label As String)
Console.WriteLine(ControlChars.Cr + label)
Dim i As Integer
For i = 0 To dv.Count - 1
Console.WriteLine(dv(i)("myColumn"))
Next i
End Sub
[C#]
private void DemonstrateRowState(){
int i;
// Create a DataTable with one column.
DataTable myTable = new DataTable("myTable");
DataColumn myColumn = new DataColumn("myColumn");
myTable.Columns.Add(myColumn);
// Add ten rows.
DataRow myRow;
for(i = 0;i < 10 ;i++) {
myRow = myTable.NewRow();
myRow["myColumn"] = "item " + i;
myTable.Rows.Add(myRow);
}
myTable.AcceptChanges();
// Create a DataView with the table.
DataView myView = new DataView(myTable);
// Change one row's value:
myTable.Rows[1]["myColumn"] = "Hello";
// Add one row:
myRow = myTable.NewRow();
myRow["myColumn"] = "World";
myTable.Rows.Add(myRow);
// Set the RowStateFilter to display only Added and modified rows.
myView.RowStateFilter=DataViewRowState.Added | DataViewRowState.ModifiedCurrent;
// Print those rows. Output = "Hello" "World";
PrintView(myView, "ModifiedCurrent and Added");
// Set filter to display on originals of modified rows.
myView.RowStateFilter=DataViewRowState.ModifiedOriginal;
PrintView(myView,"ModifiedOriginal");
// Delete three rows.
myTable.Rows[1].Delete();
myTable.Rows[2].Delete();
myTable.Rows[3].Delete();
// Set the RowStateFilter to display only Added and modified rows.
myView.RowStateFilter=DataViewRowState.Deleted;
PrintView(myView,"Deleted");
//Set filter to display only current.
myView.RowStateFilter=DataViewRowState.CurrentRows;
PrintView(myView,"Current");
// Set filter to display only unchanged rows.
myView.RowStateFilter=DataViewRowState.Unchanged;
PrintView(myView,"Unchanged");
// Set filter to display only original rows.
myView.RowStateFilter=DataViewRowState.OriginalRows ;
PrintView(myView,"OriginalRows");
}
private void PrintView(DataView dv,string label){
Console.WriteLine("\n" + label);
for(int i = 0;i < dv.Count ;i++) {
Console.WriteLine(dv[i]["myColumn"]);
}
}
[C++]
private:
void DemonstrateRowState(){
int i;
// Create a DataTable with one column.
DataTable* myTable = new DataTable(S"myTable");
DataColumn* myColumn = new DataColumn(S"myColumn");
myTable->Columns->Add(myColumn);
// Add ten rows.
DataRow* myRow;
for(i = 0;i < 10 ;i++) {
myRow = myTable->NewRow();
myRow->Item[S"myColumn"] = String::Format( S"item {0}", __box(i));
myTable->Rows->Add(myRow);
}
myTable->AcceptChanges();
// Create a DataView with the table.
DataView* myView = new DataView(myTable);
// Change one row's value:
myTable->Rows->Item[1]->Item[S"myColumn"] = S"Hello";
// Add one row:
myRow = myTable->NewRow();
myRow->Item[S"myColumn"] = S"World";
myTable->Rows->Add(myRow);
// Set the RowStateFilter to display only Added and modified rows.
myView->RowStateFilter= static_cast<DataViewRowState>
(DataViewRowState::Added | DataViewRowState::ModifiedCurrent);
// Print those rows. Output = "Hello" "World";
PrintView(myView, S"ModifiedCurrent and Added");
// Set filter to display on originals of modified rows.
myView->RowStateFilter=DataViewRowState::ModifiedOriginal;
PrintView(myView,S"ModifiedOriginal");
// Delete three rows.
myTable->Rows->Item[1]->Delete();
myTable->Rows->Item[2]->Delete();
myTable->Rows->Item[3]->Delete();
// Set the RowStateFilter to display only Added and modified rows.
myView->RowStateFilter=DataViewRowState::Deleted;
PrintView(myView,S"Deleted");
//Set filter to display only current.
myView->RowStateFilter=DataViewRowState::CurrentRows;
PrintView(myView,S"Current");
// Set filter to display only unchanged rows.
myView->RowStateFilter=DataViewRowState::Unchanged;
PrintView(myView,S"Unchanged");
// Set filter to display only original rows.
myView->RowStateFilter=DataViewRowState::OriginalRows ;
PrintView(myView,S"OriginalRows");
}
void PrintView(DataView* dv,String* label){
Console::WriteLine(S"\n{0}", label);
for(int i = 0;i < dv->Count ;i++) {
Console::WriteLine(dv->Item[i]->Item[S"myColumn"]);
}
}
[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
参照
DataView クラス | DataView メンバ | System.Data 名前空間 | DataViewRowState | AddNew | Delete