Click here to Skip to main content
15,896,269 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi,

I'm converting a BindingSource which is being filtered into a DataTable so that each entry can be placed in a rich text box for a report.

I have figured out how to convert the BindingSource into a Datatable so that I can do this. But now the filter doesn't work, any help will be appreciated.


VB
Dim dt As DataTable = New DataTable()
QryMaintenanceBindingSource.Filter = "Site like '" & cmbSite.Text & "'"
dt = CType(QryMaintenanceBindingSource.DataSource.Tables(QryMaintenanceBindingSource.DataMember), DataTable) 'Don't know why or how this works.


DataGridView2.DataSource = dt
DataGridView2.Update()
DataGridView2.Refresh()


Thanks in advance

Marco
Posted

1 solution

You can use DataView for this, like so:
VB
Dim dt As DataTable = New DataTable()
Dim myDataView As New DataView(dt)
myDataView.RowFilter = "Site like '" & cmbSite.Text & "'"
myDataView.Sort = "Site" 'If you like

DataGridView2.DataSource = myDataView
 
Share this answer
 
Comments
[no name] 25-Aug-10 4:52am    
I was actually trying to transfer the bindingsource data into a datatable. But for some reason when the data is transferred the filter was not applied. The reason being that I have to read each record into a rich textbox as a report. The reading directly from the binding source is slow.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900