Click here to Skip to main content
14,880,100 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi i have mane datagridview,and i like fillter data after set datasource

int id,nvarchar(max) name

for example when user type in textbox,'my' and select from combobox select 'like'

in datagridview just view columns that name like 'my'

how do i?
Updated 26-Jun-12 2:47am

1 solution

if datacontext.selectTable1() gets a DataTable instance, then you could write
((DataTable)datagridview1.DataSource)).DefaultView.RowFilter = string.Format("name LIKE '*{0}*'",textbox.Text);
azar660 27-Jun-12 18:21pm
thank you
when i type:
((DataTable)dataGridView2.DataSource).DefaultView.RowFilter = string.Format("name LIKE '*{0}*'",textBox6.Text);

Unable to cast object of type 'SingleResult`1[test.StoredProcedure2Result]' to type 'System.Data.DataTable'.
Thomas Duwe 28-Jun-12 3:39am
As I told you, if datacontext.selectTable1() returns an instance of DataTable
you could write the above statement.

Without further information what datacontext.selectTable1() returns
I can't help you.

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