Filtering In Datagridview In Vb.Net And Also In C# 參考完整的code
其他簡易處理方法:
#1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ElementaryDataGridView.DataSource = ElementaryBindingSource
dtTableGrd = ElementaryDataGridView.DataSource
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles TextBox1.TextChanged
dtTableGrd.DefaultView.RowFilter = "SchoolName Like '%" & TextBox1.Text & "%'"
End Sub
#2
Public Class Form1
Private dtTableGrd As DataTable
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
DataGridView1.DataSource = EmployeeProfileBindingSource
dtTableGrd = EmployeeProfileBindingSource
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
dtTableGrd.DefaultView.RowFilter = "Employee_Fname Like '%" & TextBox1.Text & "%'"
End Sub
End Class
#3
BindingSource.Filter = String.Format("{0} = '{1}'", "column name here", "filter value here")
#4
Private Sub txt_search_TextChanged(sender As System.Object, e As System.EventArgs) Handles txt_search.TextChanged
BindingSource1.Filter = String.Format("{0} LIKE '{1}%'", "user", txt_search.Text)
BindingSource1.Sort = "user ASC"
End Sub
Private Sub txt_search_Validated(sender As System.Object, e As System.EventArgs) Handles txt_search.Validated
If txt_search.Text = String.Empty Then
BindingSource1.RemoveFilter()
Else
BindingSource1.Filter = String.Format("{0} = '{1}'", "user", txt_search.Text)
BindingSource1.Sort = "user ASC"
End If
End Sub
沒有留言:
張貼留言