如何在VB 2010中筛选数据网格 [英] How to Filter a Datagrid in VB 2010

查看:84
本文介绍了如何在VB 2010中筛选数据网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在VB 2010 Express中过滤数据网格.我已经建立了到数据源的连接,并且可以在网格上看到完整的数据库,但是我不确定如何过滤网格本身.我放置了一个文本框,我想使用该文本框输入关键字,然后在按Enter键时运行过滤器.帮助! Rich,谢谢.

I''m trying to filter a datagrid in VB 2010 express. I''ve already made the connection to the datasource and can see the complete db on the grid, but I''m not sure how to filter the grid itself. I have a text box placed that I want to use to enter keywords and then run the filter when Enter is pressed. Help! Thanks, Rich.

推荐答案

您应该在Code Project的此处搜索文章页面.有几个很好的例子.

这个-具有内置过滤器的 DataGrid [ DataGridView的过滤器对话框 [
You should search the articles page here on Code Project. There are several good examples.

This one - DataGrid with built in filter[^] is in C#.

This one - A Filter Dialog for a DataGridView[^] is in VB and does much the same thing in a different way.

Have a look round and see if there is something more suited to your scenario, otherwise the two above might give you some ideas.

I have assumed that you meant the DataGridView control as you did not say it was ASP.Net

BTW the search term I used was ''filter datagridview''


好,我对此很陌生,不需要任何复杂的东西.我正在尝试采取一些小步骤.我有一个查询,该查询在对数据进行硬编码时会起作用.我想要更大的灵活性,所以我创建了一个带有文本框的查询工具栏.我想,如果我能找到如何编写SQL以便它可以基于toolstrip文本框中的字符串运行查询的话,那会很好.我只是不知道如何在工具栏文本框中使SQL看起来像要在SQL构建器中搜索的字符串.
OK, I''m pretty new at this and I don''t need anything complex. I''m trying to take small steps. I have a query built that works when I hard code data in it. I would like more flexibility so I created a toolstrip with a textbox for the query. If I could just find out how to write the SQL so it can run the query based on the string in the toolstrip textbox, that would do nicely, I think. I just don''t know how to make the SQL look in the toolstrip textbox for the string to search for in the SQL builder.


最新文章发布后:

您所需要的称为参数化查询.

基本上,这是您当前使用的查询,但是使用特殊标记代替了可变数据.用户在文本框中键入的任何内容都会替换该标记.

示例 [ ^ ].我不认为这是最好的例子,它只是在 参数化查询vb.net 上进行搜索而在Google上引起的第一枪.

一种使用此方法的方法是挂接到TextBoxLeave事件.在事件处理程序中,将其与上面链接的示例中使用的Method结合起来
After your latest post:

What you need is called a Parameterized Query.

Which is basically the query you currently use but with a special marker in place of the changeable data. The marker gets replaced with whatever the user types into the textbox.

An example[^]. I don''t think that this is the best example out there, it is simply the first hit on google from a search on parameterized queries vb.net.

One way to use this would be to hook up to the Leave event of your TextBox. Combining that with the Method used in the example linked to above, in the event handler
private void myTextBox_Leave(object sender, EventArgs e)
{
    ' obviously for your situation you would only need one string here
    DisplayPersonData(myTextBox.Text, someotherstring)
}



如果您在理解上面的链接时遇到问题,请自行搜索.那里有很多很好的例子.

祝你好运. :)

如果您需要更多帮助,而不是添加答案,请单击此答案底部的添加评论"小部件.这样一来,我会收到通知(因为这是我偶然发现的第二点).或者,如果您希望有其他人,请提出一个新问题并链接到该问题. :)



If you have problems understanding the link above then please search for yourself. There are loads of good examples out there.

Good Luck. :)

If you need more help, rather than add an answer, click on the ''Add Comment'' widget at the bottom of this answer. That way I''ll get notified (as it is I only found your second point by accident). Or if you would rather have someone else, start a new question and link to this one. :)


这篇关于如何在VB 2010中筛选数据网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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