Click here to Skip to main content
11,705,610 members (52,317 online)
Click here to Skip to main content

Tagged as

Access the Data Rows Filtered by the BindingSource.Filter Property

, 12 Mar 2010 CPOL 35.8K 9
Rate this:
Please Sign up or sign in to vote.
I recently had created a windows forms application in VB.Net2008 and made use of the BindingSource control to bind all the forms controls to the underlying SQL Queried data.I built user functionality on the form to allow the user to further filter (client side filtering ) the original data...
I recently had created a windows forms application in VB.Net2008 and made use of the BindingSource control to bind all the forms controls to the underlying SQL Queried data.

I built user functionality on the form to allow the user to further filter (client side filtering ) the original data without having to re-query the database.

The BindingSource.Filter property acts like a WHERE clause in SQL and depending on the underlying data will support statements such as "Field = 'xyz'" or "Field Not In('a','b','c')"

I was looking for a method of accessing the filtered row set as a data table to make use of the WriteXML function to export the data to file, after many hours reading the documentation and searching the net, it was still not very clear. Putting together snippets from various places I arrived at the following code to meet my needs.

After performing the initial query on the database and then setting the BindingSource.Filter property, the required data can be accessed via BindingSource.List

To expose the filtered data as a standalone data table the following code can be used to obtain the rows from the binding source;

Dim dv as DataView = ctype(BindingSource.List, DataView)
Dim dt as DataTable = dv.ToTable()

All the filtered data rows are now accessible from the new data table.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

DaveAuld
Engineer
Scotland Scotland
I have been working in the Oil & Gas Industry for over 25 years now.

Core Discipline is Instrumentation and Control Systems.

Completed Bsc Honours Degree (B29 in Computing) with the Open University in 2012.

Currently, Offshore Installation Manager in the Al Shaheen oil field, which is located off the coast of Qatar.

Prior to this, 25 years of North Sea Oil & Gas experience.

You may also be interested in...

Comments and Discussions

 
GeneralReason for my vote of 5 fantastic..only place I've been able... Pin
rborob8-Jul-10 5:01
memberrborob8-Jul-10 5:01 
QuestionWTF? Pin
daveauld10-Jan-10 10:10
memberdaveauld10-Jan-10 10:10 
AnswerRe: WTF? Pin
Rajesh R Subramanian13-Jan-10 8:57
mvpRajesh R Subramanian13-Jan-10 8:57 
GeneralRe: WTF? Pin
0x3c013-Jan-10 9:17
member0x3c013-Jan-10 9:17 
Seconded.


AnswerRe: WTF? Pin
GlimmerMan2-Feb-10 3:20
memberGlimmerMan2-Feb-10 3:20 
GeneralRe: WTF? Pin
daveauld2-Feb-10 3:23
memberdaveauld2-Feb-10 3:23 
GeneralRe: WTF? Pin
GlimmerMan2-Feb-10 4:04
memberGlimmerMan2-Feb-10 4:04 
GeneralRe: WTF? Pin
kevininstructor4-Sep-13 11:02
memberkevininstructor4-Sep-13 11:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150819.1 | Last Updated 13 Mar 2010
Article Copyright 2010 by DaveAuld
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid