如何在VS 2010上过滤DataGrid [英] how to filter datagrid on VS 2010
本文介绍了如何在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 yourDateTimePicker1_ValueChanged
method, you create anotherDataGridView
. This is fine, if you want the filtered data to be in a different DGV but if so you must add it to theControls
collection of yourForm
Me.Controls.Add(DataGridView1)
,将其设置为Location
和Size
等.
另一方面,如果您希望将过滤后的数据显示在现有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屋!
查看全文