Public Class Form1
Dim ds As New DataSet
Dim bndSourceGrid As New BindingSource()
Dim db As New DataClasses1DataContext()
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim CS = From c In db.TblCustomers Order By c.IDCustomers
Select New With {c.IDCustomers, c.NameCustomers}
'/*--------------------------------------------
dgvProducts.DataSource = CS.ToList
End Sub
Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvProducts.CellContentClick
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
LoadProducts()
End Sub
Private Sub LoadProducts()
' Using connection As New SqlConnection(connectionString)
'Dim command As New SqlCommand(queryString, connection)
'Like TextBox1.Text.Trim()
Dim CS = From c In db.TblCustomers
Where c.NameCustomers Like "'%" & TextBox1.Text.Trim() & "%'"
Select New With {c.IDCustomers, c.NameCustomers}
'/*--------------------------------------------
dgvProducts.DataSource = CS
'/*--------------------------------------------
dgvProducts.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
dgvProducts.AllowUserToResizeColumns = True
dgvProducts.Refresh()
End Sub
End Class
Tag : .NET, VB.NET, VS 2010 (.NET 4.x), VS 2012 (.NET 4.x)
Dim custs = From cust In db.TblCustomers
Where (cust.NameCustomers.StartsWith("'%" & TextBox1.Text.Trim() & "%'"))
Order By cust.IDCustomers
Select cust.IDCustomers, cust.NameCustomers