----
CodeGuru 涵蓋與 Microsoft 相關的軟件開發、移動開發、數據庫管理和 Web 應用程序編程相關的主題。 除了教程序員如何使用 Microsoft 相關語言和框架(如 C# 和 .Net)進行編碼的教程和操作方法外,我們還發布了有關軟件開發工具的文章、最新的開發人員新聞以及對項目經理的建議。 Microsoft Azure 等雲服務和 SQL Server 和 MSSQL 等數據庫選項也經常包含在內。
----
----
CodeGuru 涵蓋與 Microsoft 相關的軟件開發、移動開發、數據庫管理和 Web 應用程序編程相關的主題。 除了教程序員如何使用 Microsoft 相關語言和框架(如 C# 和 .Net)進行編碼的教程和操作方法外,我們還發布了有關軟件開發工具的文章、最新的開發人員新聞以及對項目經理的建議。 Microsoft Azure 等雲服務和 SQL Server 和 MSSQL 等數據庫選項也經常包含在內。
----
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
Imports System.Runtime.InteropServices
Public Class Form1
Private Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Integer, ByVal lpfn As KeyboardProc, ByVal hmod As IntPtr, ByVal dwThreadId As Integer) As IntPtr
Private Declare Function CallNextHookEx Lib "user32" (ByVal hhk As IntPtr, ByVal nCode As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hhk As IntPtr) As Boolean
Private Delegate Function KeyboardProc(ByVal nCode As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
Private Const WM_KEYDOWN As Integer = &H100
Private Const WH_KEYBOARD_LL As Integer = 13
Private hHook As IntPtr
Private Function KeyboardProcHandler(ByVal nCode As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
If nCode >= 0 AndAlso wParam = WM_KEYDOWN Then
Dim vkCode As Integer = Marshal.ReadInt32(lParam)
MessageBox.Show("Key Code: " & vkCode)
End If
Return CallNextHookEx(hHook, nCode, wParam, lParam)
End Function
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
hHook = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf KeyboardProcHandler, IntPtr.Zero, 0)
End Sub
Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
UnhookWindowsHookEx(hHook)
End Sub
End Class
Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, _
ByVal keyData As System.Windows.Forms.Keys) _
As Boolean
If msg.WParam.ToInt32() = CInt(Keys.Enter) Then
SendKeys.Send("{Tab}")
Return True
End If
Return MyBase.ProcessCmdKey(msg, keyData)
End Function
Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean
Dim keyCode As Keys = CType(msg.WParam, IntPtr).ToInt32
Const WM_KEYDOWN As Integer = &H100
If msg.Msg = WM_KEYDOWN AndAlso keyCode = Keys.Enter _
AndAlso Me.ActiveControl.GetType.Name = "TextBox" Then
Me.SelectNextControl(Me.ActiveControl, True, True, False, True)
Return True
End If
Return MyBase.ProcessCmdKey(msg, keyData)
End Function
Public Class Form1
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Integer) As Integer
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If GetAsyncKeyState(Keys.L) Then
MsgBox("Tada!")
End If
End Sub
End Class