次の方法で共有


How to: Filter and Sort Data in a Windows Forms Application

You filter data by setting the Filter property to a string expression that returns the desired records.

You sort data by setting the Sort property to the column name you want to sort on; append DESC to sort in descending order, or append ASC to sort in ascending order.

Note

If your application does not use BindingSource components, then you can filter and sort data using DataView objects. For more information, see Creating and Using DataViews.

To filter data using a BindingSource component

  • Set the Filter property to the expression you want to return. For example, the following code returns customers with a CompanyName that starts with "B":

    CustomersBindingSource.Filter = "CompanyName like 'B'"
    
    customersBindingSource.Filter = "CompanyName like 'B'";
    

To sort data using a BindingSource component

  • Set the Sort property to the column you want to sort on. For example, the following code sorts customers on the CompanyName column in descending order:

    CustomersBindingSource.Sort = "CompanyName Desc"
    
    customersBindingSource.Sort = "CompanyName Desc";
    

See Also

Concepts

Binding Windows Forms Controls to Data in Visual Studio

Preparing Your Application to Receive Data

Fetching Data into Your Application

Binding Controls to Data in Visual Studio

Editing Data in Your Application

Validating Data

Saving Data

Other Resources

Data Walkthroughs

Overview of Data Applications in Visual Studio

Connecting to Data in Visual Studio