如何过滤datafridview表并将其显示到另一个表中 [英] How to filter a datafridview table and show it into another table

查看:123
本文介绍了如何过滤datafridview表并将其显示到另一个表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨大家好:



我正在使用Windows Forms C#来开发我的应用程序。在我的表单中,我有2个datagridview(dataGridView1和dataGridView2)。 dataGridView1是一个数据源表。在我的表中,我有PurchaseDateTime。我有用户条目的DateTimePicker。



我想通过更改dateTimePicker中的值来过滤dataGridView1,并将过滤后的数据显示到dataGridView2中。



我在网上冲了很多,但没有找到任何有用的东西。

如果你能帮我,我很感激。

Hi Guys:

I am using Windows Forms C# to develop my application. In my form I have 2 datagridview ( dataGridView1 and dataGridView2) . dataGridView1 is boud to a datasource table. In my table I have PurchaseDateTime. I have DateTimePicker for the user entry.

I want to filter my dataGridView1 by the change of value in my dateTimePicker and show the filtered data into dataGridView2.

I surfed the webs alot, but didn''t find anything useful.
I appreciate if you help me.

推荐答案

在datepicker'的valuechanged事件中你可以做类似的事情



On the datepicker''s valuechanged event you can do something like this

DataSet ds = ((BindingSource)(dataGridView1.DataSource)).DataSource as DataSet;            
            DataRow[] res = ds.Tables[0].Select("date = ''" + dateTimePicker1.Value.ToShortDateString() + "''");
            dataGridView2.DataSource = res;


这篇关于如何过滤datafridview表并将其显示到另一个表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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