Imports System.Data
Imports System.Data.SqlServerCe
Imports System.Data.SqlTypes
Imports System.Drawing
Imports System.ComponentModel
Imports System.Windows.Forms
Public Class MemberSearch
Inherits System.Windows.Forms.Form
Private WithEvents songsDataGridView As New System.Windows.Forms.DataGridView
Private strKeyWord As String = ""
Private Sub MemberSearch_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PopulateData()
End Sub
Private Sub BtSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtSearch.Click
strKeyWord = Me.TxtSearch.Text
PopulateData()
End Sub
Private Sub PopulateData()
Dim myConnection As SqlCeConnection
Dim dt As New DataTable
Dim Adapter As SqlCeDataAdapter
myConnection = New SqlCeConnection("Data Source=E:\sasitornpro\sasitornpro\MyDatabase#1.sdf;")
myConnection.Open()
Dim myCommand As SqlCeCommand = myConnection.CreateCommand()
myCommand.CommandText = "SELECT * FROM member WHERE 1=1 "
myCommand.CommandType = CommandType.Text
Dim strSQL As String = "SELECT * FROM member WHERE 1=1 "
If strKeyWord <> "" Then
strSQL = strSQL & " AND Name Like '%" & strKeyWord & "%' "
End If
Adapter = New SqlCeDataAdapter(strSQL, myConnection)
Adapter.Fill(dt)
myConnection.Close()
Adapter = Nothing
Me.DgName.DataSource = dt
Me.DgName.Columns.Clear()
With DgName.ColumnHeadersDefaultCellStyle
.BackColor = Color.Navy
.ForeColor = Color.White
.Font = New Font(songsDataGridView.Font, FontStyle.Bold)
End With
Dim ColumnTextBox As DataGridViewTextBoxColumn
'*** Column (Select) ***'
Dim ColumnCheckBox As New DataGridViewCheckBoxColumn()
ColumnCheckBox.Width = 30
ColumnCheckBox.DataPropertyName = "Select"
Me.DgName.Columns.Add(ColumnCheckBox)
'*** Checkbox in Header ***'
Dim ckBox As New CheckBox()
Dim rect As Rectangle = DgName.GetCellDisplayRectangle(0, -1, True)
ckBox.Size = New Size(18, 18)
rect.X = rect.Location.X + (rect.Width / 4)
ckBox.Location = rect.Location
AddHandler ckBox.CheckedChanged, New EventHandler(AddressOf ckBox_CheckedChanged)
Me.DgName.Controls.Add(ckBox)
DgName.Columns(0).Frozen = False
'*** Column (CustomerID) ***'
ColumnTextBox = New DataGridViewTextBoxColumn()
ColumnTextBox.DataPropertyName = "member_id"
ColumnTextBox.HeaderText = "รหัส"
ColumnTextBox.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
ColumnTextBox.Width = 100
Me.DgName.Columns.Add(ColumnTextBox)
'*** Column (Name) ***'
ColumnTextBox = New DataGridViewTextBoxColumn()
ColumnTextBox.DataPropertyName = "member_name"
ColumnTextBox.HeaderText = "ชื่อ"
ColumnTextBox.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
ColumnTextBox.Width = 100
Me.DgName.Columns.Add(ColumnTextBox)
'*** Column (Email) ***'
ColumnTextBox = New DataGridViewTextBoxColumn()
ColumnTextBox.DataPropertyName = "member_address"
ColumnTextBox.HeaderText = "ที่อยู่"
ColumnTextBox.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
ColumnTextBox.Width = 100
Me.DgName.Columns.Add(ColumnTextBox)
'*** Column (CountryCode) ***'
ColumnTextBox = New DataGridViewTextBoxColumn()
ColumnTextBox.DataPropertyName = "member_count"
ColumnTextBox.HeaderText = "แต้มสะสม"
ColumnTextBox.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
ColumnTextBox.Width = 100
Me.DgName.Columns.Add(ColumnTextBox)
End Sub
Private Sub ckBox_CheckedChanged()
Dim i As Integer = 0
For j As Integer = 0 To Me.DgName.RowCount - 1
Me.DgName(0, j).Value = True
Next
End Sub
<STAThreadAttribute()> _
Public Shared Sub Main()
Application.EnableVisualStyles()
Application.Run(New Form1())
End Sub
End Class