Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
SerachGrid("select * from AreaMaster where AreaID like '%" & ComboBox1.Text & "%'")
Dim use As String
Dim passs As String
use = Class1.uss
passs = Class1.pass
' SerachGrid("select * from AreaMaster where Area 'txtarea.Text' ")
Dim connectionString As String = "Server=PONGWICS2014-PC;UID=" & use & ";PASSWORD=" & passs & ";Database=Top_CustomerEntry;Connect Timeout=200; pooling='true'; Max Pool Size=200"
Dim ds As New DataSet
Dim connection As New SqlConnection(connectionString)
'ComboBox1.Items.Clear()
Dim sql As String = "SELECT AreaID,Area,Team,ZuelligArea FROM AreaMaster Where AreaID = '" & ComboBox1.Text & "'"
' Me.txtarea.Text = Me.ComboBox1.SelectedItem("Area")
'Me.txtteam.Text = Me.ComboBox1.SelectedItem("Team")
'Me.txtzuellig.Text = Me.ComboBox1.SelectedItem("ZuelligArea")
'Dim strID As String = Me.DataGridView1(0, Me.DataGridView1.CurrentCell.RowIndex).Value.ToString()
'Dim myConnection As SqlConnection
'myConnection = New SqlCeConnection("Data Source =" + (System.IO.Path.GetDirectoryName( System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase ) + "\Database1.sdf;"))
' myConnection.Open()
' Dim myCommand As SqlCommand = myConnection.CreateCommand()
connection.Open()
Dim i As Integer
'sTable = sDs.Tables("Area")
' Dim ds As DataSet = New DataSet
'sAdapter.Fill(ds, "AreaMaster")
'sTable = sDs.Tables("Area")
ComboBox1.ValueMember = "AreaID"
ComboBox1.DisplayMember = "AreaID"
ComboBox1.Text = ComboBox1.SelectedValue
'If sDs.Tables("AreaID").Rows.Count <> 0 Then
'If IsDBNull(ds.Tables("AreaMaster").Rows(i)("txtteam.Text")) Then
'Name = "null"
'Else
'Name = ds.Tables("AreaMaster").Rows(i)("txtteam.Text")
'End If
ComboBox1.ValueMember = "Area"
ComboBox1.DisplayMember = "AreaID"
txtarea.Text = ComboBox1.SelectedValue
ComboBox1.ValueMember = "Team"
ComboBox1.DisplayMember = "AreaID"
txtteam.Text = ComboBox1.SelectedValue
ComboBox1.ValueMember = "ZuelligArea"
ComboBox1.DisplayMember = "AreaID"
txtzuellig.Text = ComboBox1.SelectedValue
'End If
'sDs = New DataSet()
'sAdapter.Fill(sDs, "AreaID")
'sTable = sDs.Tables("Area")
'txtarea.Text = ComboBox1.SelectedValue.ToString()
'txtteam.Text = ComboBox1.SelectedValue.ToString()
'txtzuellig.Text = ComboBox1.SelectedValue.ToString()
'sCommand = New SqlCommand(sql, connection)
'sb = New StringBuilder
sAdapter = New SqlDataAdapter(sCommand)
'sBuilder = New SqlCommandBuilder(sAdapter)
'sDs = New DataSet()
SerachGrid("select * from AreaMaster where AreaID like '%" & ComboBox1.Text & "%'")
' ComboBox1.SelectedIndex = -1
Dim dsd As DataSet = Nothing
Return
connection.Close()
For i = 0 To sAdapter.Fill(ds, "AreaID") - 1
'ComboBox1.Text.Add(ds.Tables("AreaID").Rows(i)("AreaMaster").ToString)
Next
'ComboBox1.Refresh()
End Sub
Private Sub ComboBox1_SelectedIndexChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
SerachGrid("select * from AreaMasterNew where AreaID like '%" & ComboBox1.Text & "%'")
Dim use As String
Dim passs As String
use = Class1.uss
passs = Class1.pass
' SerachGrid("select * from AreaMaster where Area 'txtarea.Text' ")
Dim connectionString As String = "Server=N-PC;UID=sa;PASSWORD= Pong;Database=Top_CustomerEntry;Connect Timeout=200; pooling='true'; Max Pool Size=200"
Dim ds As New DataSet
Dim connection As New SqlConnection(connectionString)
Dim sql As String = "SELECT AreaID,Area,Team,ZuelligArea FROM AreaMaster Where AreaID = '" & ComboBox1.Text & "'"
' myConnection.Open()
' Dim myCommand As SqlCommand = myConnection.CreateCommand()
connection.Open()
Dim i As Integer
'sTable = sDs.Tables("Area")
' Dim ds As DataSet = New DataSet
'sAdapter.Fill(ds, "AreaMaster")
'sTable = sDs.Tables("Area")
ComboBox1.ValueMember = "Area"
ComboBox1.DisplayMember = "AreaID"
txtarea.Text = ComboBox1.SelectedValue
ComboBox1.ValueMember = "Team"
ComboBox1.DisplayMember = "AreaID"
txtteam.Text = ComboBox1.SelectedValue
ComboBox1.ValueMember = "ZuelligArea"
ComboBox1.DisplayMember = "AreaID"
txtzuellig.Text = ComboBox1.SelectedValue
sAdapter = New SqlDataAdapter(sCommand)
'sBuilder = New SqlCommandBuilder(sAdapter)
'sDs = New DataSet()
SerachGrid("select * from AreaMasterNew where AreaID like '%" & ComboBox1.Text & "%'")
' ComboBox1.SelectedIndex = -1
Dim dsd As DataSet = Nothing
End Sub
Private Sub comboBox1_KeyUp(sender As Object, e As KeyEventArgs)
If comboBox1.Text = "" Then
Else
conn.Open()
Dim cmd As SqlCommand = conn.CreateCommand()
cmd.CommandType = CommandType.Text
cmd.CommandText = "select EMPLOYEE_CODE,EMPLOYEE_NAME_THAI,EMPLOYEE_SURNAME_THAI from MT_EMPLOYEE where EMPLOYEE_NAME_THAI like('" & comboBox1.Text & "%') AND IS_DRIVER=1 OR EMPLOYEE_CODE like('" & comboBox1.Text & "%') AND IS_DRIVER=1"
Dim dt As New DataTable()
Dim da As New SqlDataAdapter(cmd)
da.Fill(dt)
dataGridView1.DataSource = dt
conn.Close()
End If
End Sub
*'มันทำงานแค่ครั้งเดียวนะครับ Load จนกว่าคุณจะ Unload/Closing ไป
'*
Private Sub AreaMaster_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
ComboBox1.DataSource = yourDataTable
ComboBox1.ValueMember = "AreaID"
ComboBox1.DisplayMember = "AreaID"
ComboxBox1.SelectedIndex = 1 'สมมุติว่าต้องการเลือกรายการที่สอง
End sub
Private Sub ComboBox1_TextChanged(sender As Object, e As System.EventArgs) Handles ComboBox1.TextChanged
SearchGrid
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
SearchGrid
End Sub
ปล. Windows Application TextChanged Events และ Web Application TextChaged Events
ผลลัพท์เหมือนกันแต่วิธีการทำงานแตกต่างกันครับ (โดยคำนึงถึงความจริง)
Private Sub ComboBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.TextChanged
Dim use As String
Dim passs As String
use = Class1.uss
passs = Class1.pass
Label5.Text = ComboBox1.Text
Dim connectionString As String = "Server=N-PC;UID=" & use & ";PASSWORD=" & passs & ";Database=Top_CustomerEntry;Connect Timeout=200; pooling='true'; Max Pool Size=200"
Dim st As String = "Select Area from AreaMasterNew WHERE AreaID = " & Label5.Text & ""
Dim st1 As String = "Select Team from AreaMasterNew WHERE AreaID = " & Label5.Text & ""
Dim st2 As String = "Select ZuelligArea from AreaMasterNew WHERE AreaID = " & Label5.Text & ""
SerachGrid("select * from AreaMasterNew where AreaID like '%" & ComboBox1.Text & "%'")
Dim connection As New SqlConnection(connectionString)
Dim da As New SqlDataAdapter(st, connection) 'Connection
Dim ds As New DataSet
Dim da1 As New SqlDataAdapter(st1, connection)
Dim ds1 As New DataSet
Dim da2 As New SqlDataAdapter(st2, connection)
Dim ds2 As New DataSet
'ComboBox1.Items.Clear()
connection.Open()
Try
da.Fill(ds, "AreaID")
TextBox2.Text = ds.Tables("AreaID").Rows(0).Item("Area").ToString
Catch ex As Exception
Label5.Text = ComboBox1.Text
End Try
Try
da2.Fill(ds2, "AreaID")
TextBox3.Text = ds2.Tables("AreaID").Rows(0).Item("ZuelligArea").ToString
Catch ex As Exception
Label5.Text = ComboBox1.Text
End Try
Try
da1.Fill(ds1, "AreaID")
TextBox4.Text = ds1.Tables("AreaID").Rows(0).Item("Team").ToString
Catch ex As Exception
Label5.Text = ComboBox1.Text
End Try
connection.Close()
'ComboBox1.SelectedIndex = -1
'Call ClearTextBoxes(Me)
End Sub