Click here to Skip to main content
16,008,075 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have a Datagridview full of data, from a Dataset, I'm using access.
I also have a Multiline Textbox and a Button to execute the code in the Onclick event.

I want to show the Datagridview rows that match with the lines in the Multiline Textbox.

For example: my Datagridview have two columns: "Name" and "Last_Name"...

In the Textbox when I type in the first line 'John' and in the second line I type 'Mary', I want the Datagridview to show me only the rows that have these names in the "Name" Column. So in the Datagridview we'll have two rows 'John' in one row and 'Mary' in the other row, and if I keep typing in others lines into the Multiline Textbox keep doing the or search and/or filter...

Can someone help me with this please?

Thanks in advance!
Posted
Comments
Aditya Mangipudi 6-Aug-12 9:27am    
Can you post some code? Where exactly are you having problems?
[no name] 6-Aug-12 9:29am    
Help with what? The only question in here is, "Can someone help me with this please?". What is the specific problem that you have? Where is the code that demonstrates this problem?

If you are going to hard code this the only option I see is to use this code here:
http://social.msdn.microsoft.com/Forums/en/wpf/thread/a5fd5413-f055-4b56-83af-6d6bdb1d6fe9[^]

The esayer thing, and fare more efficient thing is to do a search in the DataTable that you bind the DataGridView to, and you could highlight it with the code in the first link.

There is also the question on what to filter the data with, Id use either link or the build in filter function in the DataGridVeiw-
 
Share this answer
 
Thanks for answering!

I got something, it's close but the issue is that I'll need to write any single line that I'd like to use in the Multiline Textbox, not good...

Would be great do it with a simple code or a loop or some like that.

Hope somebody helps!

Code Below, Thanks,




C#
string[] lines = textBox1.Lines;


         string sql = "Select Name_Column FROM Database";


         OleDbDataAdapter da = new OleDbDataAdapter();
         da = new OleDbDataAdapter(sql, conneccionDB);
         DataSet ds = new DataSet();
         da.Fill(ds, "Database");


         DataView dtv = new DataView(ds.Tables[0], "Name_Column LIKE '%" +  lines[0] + "%' OR Name_Column LIKE '%" + lines[1] + "%'", "Name_Column", DataViewRowState.CurrentRows);

          lineIndex++;
          datagrid_catnumRef.DataSource = dtv;
 
Share this answer
 

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