DataView.RowFilter 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
DataView에서 표시할 행을 필터링하는 데 사용하는 식을 가져오거나 설정합니다.
public:
virtual property System::String ^ RowFilter { System::String ^ get(); void set(System::String ^ value); };
public virtual string? RowFilter { get; set; }
public virtual string RowFilter { get; set; }
[System.Data.DataSysDescription("DataViewRowFilterDescr")]
public virtual string RowFilter { get; set; }
member this.RowFilter : string with get, set
[<System.Data.DataSysDescription("DataViewRowFilterDescr")>]
member this.RowFilter : string with get, set
Public Overridable Property RowFilter As String
속성 값
행의 필터링 방법을 지정하는 문자열입니다.
- 특성
예제
다음 예제에서는 을 DataView 만들고 해당 RowFilter 속성을 설정합니다.
using System;
using System.Data;
using System.Windows.Forms;
public class Form1 : Form {
protected TextBox Text1;
protected DataSet DataSet1;
public static void Main() {
DemostrateDataView();
}
private static void DemostrateDataView() {
// Create a DataTable with one column
DataTable dt = new DataTable("MyTable");
DataColumn column = new DataColumn("Col", typeof(int));
dt.Columns.Add(column);
// Add 5 rows on Added state
for (int i = 0; i < 5; i++) {
DataRow row = dt.NewRow();
row["Col"] = i;
dt.Rows.Add(row);
}
// Add 5 rows on Unchanged state
for (int i = 5; i < 10; i++) {
DataRow row = dt.NewRow();
row["Col"] = i;
dt.Rows.Add(row);
// Calling AcceptChanges will make the DataRowVersion change from Added to Unchanged in this case
row.AcceptChanges();
}
// Create a DataView
DataView dv = new DataView(dt);
Console.WriteLine("Print unsorted, unfiltered DataView");
PrintDataView(dv);
// Changing the Sort order to descending
dv.Sort = "Col DESC";
Console.WriteLine("Print sorted DataView. Sort = 'Col DESC'");
PrintDataView(dv);
// Filter by an expression. Filter all rows where column 'Col' have values greater or equal than 3
dv.RowFilter = "Col < 3";
Console.WriteLine("Print sorted and Filtered DataView by RowFilter. RowFilter = 'Col > 3'");
PrintDataView(dv);
// Removing Sort and RpwFilter to ilustrate RowStateFilter. DataView should contain all 10 rows back in the original order
dv.Sort = String.Empty;
dv.RowFilter = String.Empty;
// Show only Unchanged rows or last 5 rows
dv.RowStateFilter = DataViewRowState.Unchanged;
Console.WriteLine("Print Filtered DataView by RowState. RowStateFilter = DataViewRowState.Unchanged");
PrintDataView(dv);
}
private static void PrintDataView(DataView dv) {
// Printing first DataRowView to demo that the row in the first index of the DataView changes depending on sort and filters
Console.WriteLine("First DataRowView value is '{0}'", dv[0]["Col"]);
// Printing all DataRowViews
foreach (DataRowView drv in dv) {
Console.WriteLine("\t {0}", drv["Col"]);
}
}
}
Imports System.Data
Imports System.Windows.Forms
Public Class Form1
Inherits Form
Protected Text1 As TextBox
Protected DataSet1 As DataSet
Public Shared Sub Main()
DemostrateDataView()
End Sub
Private Shared Sub DemostrateDataView()
' Create a DataTable with one column
Dim dt As New DataTable("MyTable")
Dim column As New DataColumn("Col", GetType(Integer))
dt.Columns.Add(column)
' Add 5 rows on Added state
For i As Integer = 0 To 4
Dim row As DataRow = dt.NewRow()
row("Col") = i
dt.Rows.Add(row)
Next
' Add 5 rows on Unchanged state
For i As Integer = 5 To 9
Dim row As DataRow = dt.NewRow()
row("Col") = i
dt.Rows.Add(row)
' Calling AcceptChanges will make the DataRowVersion change from Added to Unchanged in this case
row.AcceptChanges()
Next
' Create a DataView
Dim dv As New DataView(dt)
Console.WriteLine("Print unsorted, unfiltered DataView")
PrintDataView(dv)
' Changing the Sort order to descending
dv.Sort = "Col DESC"
Console.WriteLine("Print sorted DataView. Sort = 'Col DESC'")
PrintDataView(dv)
' Filter by an expression. Filter all rows where column 'Col' have values greater or equal than 3
dv.RowFilter = "Col < 3"
Console.WriteLine("Print sorted and Filtered DataView by RowFilter. RowFilter = 'Col > 3'")
PrintDataView(dv)
' Removing Sort and RpwFilter to ilustrate RowStateFilter. DataView should contain all 10 rows back in the original order
dv.Sort = [String].Empty
dv.RowFilter = [String].Empty
' Show only Unchanged rows or last 5 rows
dv.RowStateFilter = DataViewRowState.Unchanged
Console.WriteLine("Print Filtered DataView by RowState. RowStateFilter = DataViewRowState.Unchanged")
PrintDataView(dv)
End Sub
Private Shared Sub PrintDataView(dv As DataView)
' Printing first DataRowView to demo that the row in the first index of the DataView changes depending on sort and filters
Console.WriteLine("First DataRowView value is '{0}'", dv(0)("Col"))
' Printing all DataRowViews
For Each drv As DataRowView In dv
Console.WriteLine(vbTab & " {0}", drv("Col"))
Next
End Sub
End Class
설명
값을 구성 RowFilter 하려면 열 이름 뒤에 연산자 및 필터링할 값을 지정합니다. 값은 따옴표여야 합니다. 예를 들면 다음과 같습니다.
"LastName = 'Smith'"
Expression 자세한 내용은 클래스의 DataColumn 속성을 참조하세요.
null 값이 있는 열만 반환하려면 다음 식을 사용합니다.
"Isnull(Col1,'Null Column') = 'Null Column'"
적용 대상
추가 정보
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
.NET