如何在VS 2010上过滤DataGrid [英] how to filter datagrid on VS 2010

查看:60
本文介绍了如何在VS 2010上过滤DataGrid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经加载了网格并显示在表单上,​​然后想按日期进行筛选,因为每次选择时都如此?在调试时,我可以在myDataView上看到选择行,但是无法填充或显示在表单datagrid上.

这是代码:

I have loaded my grid and has displayed on form and then wanted to filter by date as it select each time? on debug I could see select row on myDataView but can''t fill or display on form datagrid.

here is the code:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

     Me.VwGUI_Maintenance_WindowsTableAdapter.Fill(Me.CPRDataSet.vwGUI_Maintenance_Windows)

 End Sub

Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged

       Dim myDataTable As DataTable = Me.CPRDataSet.vwGUI_Maintenance_Windows
       Dim myDataView As New DataView(myDataTable)
       Dim DataGridView1 As New DataGridView()


      myDataView.RowFilter = "Activity_Date = '" & DateTimePicker1.Text.ToString & "'"
DataGridView1.DataSource = myDataView

   End Sub


推荐答案

在您的第一段中,您说您拥有网格,并且网格显示在表单上.然后,在您的DateTimePicker1_ValueChanged方法中,创建另一个DataGridView.如果您希望过滤后的数据位于其他DGV中,那么很好,但是如果这样,则必须将其添加到Form
Controls集合中
In your first paragraph you say that you have your grid and it displays on your form. Then in your DateTimePicker1_ValueChanged method, you create another DataGridView. This is fine, if you want the filtered data to be in a different DGV but if so you must add it to the Controls collection of your Form
Me.Controls.Add(DataGridView1)


,将其设置为LocationSize等.

另一方面,如果您希望将过滤后的数据显示在现有DGV中,只需将其DataSource设置为myDataView


, set it''s Location and Size etc..

On the other hand, if you wanted the filtered data to appear in the existing DGV just set it''s DataSource to myDataView


这篇关于如何在VS 2010上过滤DataGrid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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