简体   繁体   English

如何筛选使用Visual Studio创建的C#Winform datagridview

[英]How to filter C# Winform datagridview that was created with Visual Studio

I'm astonished there isn't even a filter property attached to datagridview and I'm getting on my nerve, I can find examples for filtering Datagridview that was binded programmatically, I cannot find any example on how to filter a datagridview that was generated by Visual Studio. 我很惊讶,甚至没有将过滤器属性附加到datagridview上,我也开始感到不安,我可以找到一些示例性的方法来过滤以编程方式绑定的Datagridview,但是找不到关于如何过滤所生成的datagridview的任何示例。由Visual Studio。

So please can someone tell me how to filter this stuff ? 所以,有人可以告诉我如何过滤这些东西吗?

Thanks. 谢谢。

在BindingSource上放置一个过滤器:

bindingSource.Filter = "Age < 21";

You place the filter on the DataSource that is driving your DataGridView - for example, I have this code on a DataGridView that allows for user filtering and is called on a postback: 您将筛选器放置在驱动DataGridView的DataSource上-例如,我将这段代码放置在DataGridView上,该代码允许用户筛选并在回发时调用:

VisitsDataSource.FilterExpression = "1 = 2";
GridView1.DataBind();

Take a look at this post here . 这里看看这篇文章。 You have provide a BindingSource as the DataSource of the DataGridView rather than the DataTable itself. 您提供了BindingSource作为DataGridView的数据源,而不是DataTable本身。

BindingSource source1 = new BindingSource();
source1.DataSource = yourDataTable;    

//The Filter string can include Boolean expressions.
source1.Filter = "email='samikram@live.com'"

// Set the data source for the DataGridView.
datagridview1.DataSource = source1;

Thanks JustinD, I suppose you talk about ASP.NET. 谢谢JustinD,我想您是谈论ASP.NET的。

I forgot to say I'm using Winform with BindingSource. 我忘了说我正在将Winform与BindingSource一起使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM