Setelah Form1 kita buat maka untuk membuat Form2 Yaitu :
Klik kanan di Pojok Kanan Atas Klik Add > Windows Form :
Kemudian kita atur design nya :
Karena Tombol Button Pencarian nya ada di Form1 maka cara panggil
Form2 ( Tabel Customer ) :
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
form2.Show()
End Sub
Kita beri nama TextBox nya misal txtcarib
DataGridViewnya kita beri nama dgvb
Ini Coding nya
Imports System.Data
Imports MySql.Data.MySqlClient
Public Class form2
Private Sub TampilDataG()
modul_oc.konek()
Dim da As New MySqlDataAdapter("SELECT customercode,customername,enddate,alamat,telp FROM customer", db)
Dim dt As New DataTable
da.Fill(dt)
dgvb.DataSource = dt
End Sub
Private Sub CekCustb()
txtcarib.Text = Trim(UCase(txtcarib.Text))
modul_oc.konek()
Try
strSql = "SELECT customercode,customername,enddate,alamat,telp FROM customer WHERE customername like '%" & txtcarib.Text & "%'"
cmd.CommandText = strSql
cmd.Connection = db
dadapter.SelectCommand = cmd
datardr = cmd.ExecuteReader
datardr.Read()
If datardr.HasRows Then
' datardr.Read()
'Dim da As New MySqlDataAdapter("SELECT customercode,customername,enddate,alamat,telp FROM customer WHERE customername like '%" & txtcarib.Text & "%'", db)
Dim query As String = "SELECT customercode,customername,enddate,alamat,telp FROM customer WHERE customername like '%" & txtcarib.Text & "%'"
Dim da As New MySqlDataAdapter(query, db)
Dim ds As New DataSet()
If da.Fill(ds, "ketemu") Then
dgvb.DataSource = ds.Tables("ketemu")
dgvb.ReadOnly = True
End If
Else
MsgBox("Data Tables Customer Tidak Ditemukan....!", MsgBoxStyle.Exclamation, "Informasi")
End If
' db.Close()
Catch ex As Exception
End Try
End Sub
Private Sub form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TampilDataG()
End Sub
Private Sub dgvb_CellClick(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvb.CellClick
With dgvb
Form1.txtkdcust.Text = .Item(0, .CurrentRow.Index).Value
Form1.txtnama.Text = .Item(1, .CurrentRow.Index).Value
Form1.txtalamat.Text = .Item(3, .CurrentRow.Index).Value
End With
End Sub
' Jika Data yg ada di Grid di Klik 2 X maka textbox yang ada di Form1 akan terisi Data yg terpilih
Private Sub dgvb_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgvb.DoubleClick
With dgvb
Form1.txtkdcust.Text = .Item(0, .CurrentRow.Index).Value
Form1.txtnama.Text = .Item(1, .CurrentRow.Index).Value
Form1.txtalamat.Text = .Item(3, .CurrentRow.Index).Value
Me.Close()
Form1.txtnomor.Focus()
End With
End Sub
Private Sub TampilKUST()
modul_oc.konek()
Dim da As New MySqlDataAdapter("SELECT customercode,customername,enddate,alamat,telp FROM customer WHERE customername like '%" & txtcarib.Text & "%'", db)
Dim dt As New DataTable
da.Fill(dt)
dgvb.DataSource = dt
dgvb.Refresh()
End Sub
' Dengan Memilih Pencarian di TextChanged maka data yg kita ketik
langsung cari di Grid
' Misal kita ketik w maka data yg ada w nya akan muncul / di tampilkan semua.
Private Sub txtcarib_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtcarib.TextChanged
TampilKUST()
End Sub
End Class
Tidak ada komentar:
Posting Komentar