0
A
回答
0
我真的不知道你正在嘗試做的。也許你想要某種自動完成的過程來運行。是嗎?請參閱下面的代碼示例。
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Imports System.Data.SqlClient
Namespace WindowsFormsApplication4
Public Class Form1
Inherits Form
Public Sub New()
MyBase.New
InitializeComponent
Me.initializeFields
Me.loadCustomerFromNorthwindDbToDgv1
End Sub
Private CustomerId As DataGridViewTextBoxColumn
Private CompanyName As DataGridViewTextBoxColumn
Private Address As DataGridViewTextBoxColumn
Private Sub initializeFields()
Me.CustomerId = New DataGridViewTextBoxColumn
Me.CustomerId.Name = "CustomerID"
Me.CustomerId.DataPropertyName = "CustomerID"
Me.dataGridView1.Columns.Add(Me.CustomerId)
Me.CompanyName = New DataGridViewTextBoxColumn
Me.CompanyName.Name = "CompanyName"
Me.CompanyName.DataPropertyName = "CompanyName"
Me.dataGridView1.Columns.Add(Me.CompanyName)
Me.Address = New DataGridViewTextBoxColumn
Me.Address.Name = "Address"
Me.Address.DataPropertyName = "Address"
Me.dataGridView1.Columns.Add(Me.Address)
End Sub
Private dv As DataView
Private Sub loadCustomerFromNorthwindDbToDgv1()
Dim conConnect As SqlConnection = New SqlConnection("Data Source = EXCEL-PC; Database = 'Northwind.MDF'; Integrated Security = true")
Try
Dim dAdapter As SqlDataAdapter = New SqlDataAdapter("SELECT CustomerID, CompanyName, Address FROM Customers ", conConnect)
Dim DS As DataSet = New DataSet
Dim bs As BindingSource = New BindingSource
dAdapter.Fill(DS, "dsCustomer")
Me.dataGridView1.AutoGenerateColumns = false
Dim dt As DataTable = DS.Tables("dsCustomer")
bs.DataSource = DS.Tables("dsCustomer")
Me.dv = New DataView(DS.Tables("dsCustomer"))
Me.dataGridView1.DataSource = bs
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub
'will do the search for CompanyName name everytime you type in @ the textbox search
Private Sub textBox1_TextChanged(ByVal sender As Object, ByVal e As EventArgs)
Me.dv.RowFilter = ("CompanyName like '%' + '" _
+ (textBox1.Text + "' + '%' "))
Me.dataGridView1.DataSource = Me.dv
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
' TODO: This line of code loads data into the 'northwindDataSet.Customers' table. You can move, or remove it, as needed.
Me.customersTableAdapter.Fill(Me.northwindDataSet.Customers)
End Sub
End Class
End Namespace
相關問題
- 1. DataGridView篩選
- 2. DateTimePicker篩選datagridview
- 3. 篩選器DataGridView
- 4. 篩選datagridview行
- 5. Datagridview篩選空白
- 6. SSRS檢查篩選組RowCount
- 7. 使用日期篩選datagridview
- 8. 查詢或篩選最小字段值?
- 9. 從檢查的DataGridView項目選擇值
- 10. 還記得在DataGridView檢查複選框
- 11. C#的DataGridView - 檢查行被選中
- 12. 在DataGridView中篩選相關數據
- 13. 篩選沒有數據綁定的DataGridView
- 14. DataGridView篩選器中的錯誤
- 15. 實體框架Datagridview篩選器
- 16. C#和DataGridView:篩選不起作用
- 17. 使用多個控件篩選datagridview
- 18. Datagridview篩選錯誤/ Vb.net的SQL
- 19. 高級DataGridView日期時間篩選器
- 20. DataGridView篩選OnClick事件(C#WinForm)
- 21. 按日期範圍篩選WinForms DataGridView
- 22. DataGridView搜索和篩選數據在C#
- 23. C#篩選DataGridView與數組的值
- 24. 對篩選的DataGridView執行計算
- 25. 篩選篩選的數據查看
- 26. SQL篩選查詢
- 27. 篩選表單2中的datagridview並將篩選後的數據返回到Form1中的datagridview中
- 28. 從Microsoft Access數據庫篩選搜索數據並在datagridview中篩選c#
- 29. 使用不同和/或通過篩選篩選選擇
- 30. JQuery或Javascript篩選器選擇選項