根据Multilite文本框中的每一行选择Datagridview中的行 [英] Select rows in Datagridview depending of each line in a Multilite Textbox

查看:89
本文介绍了根据Multilite文本框中的每一行选择Datagridview中的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Datagridview,其中包含来自数据集的所有数据,我正在使用访问权限.
我还具有一个多行文本框和一个按钮来执行Onclick事件中的代码.

我想显示与多行文本框中的行匹配的Datagridview行.

例如:我的Datagridview有两列:名称"和"Last_Name" ...

在文本框中,当我在第一行中键入"John",在第二行中键入"Mary"时,我希望Datagridview仅向我显示名称"列中具有这些名称的行.因此,在Datagridview中,我们将在一行中有两行"John",在另一行中有"Mary",如果我继续在Multiline Textbox中输入其他行,请继续执行or或search和/或过滤器...

有人可以帮我吗?

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!

推荐答案

如果您要进行硬编码,那么我看到的唯一选择是在此处使用此代码:
http://social.msdn.microsoft.com/Forums/zh/wpf/thread/a5fd5413-f055-4b56-83af-6d6bdb1d6fe9 [
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-


感谢您的回答!

我得到了一些东西,它接近了,但是问题是我需要写任何我想在多行文本框中使用的单行,不好…….

用一个简单的代码或一个循环或类似的东西来做是很好的.

希望有人帮忙!

下面的代码,谢谢,




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,




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;


这篇关于根据Multilite文本框中的每一行选择Datagridview中的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆