Private Sub dgv_CellMouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles dgv.CellMouseUp
If e.RowIndex = -1 Then Exit Sub
With dgvoffical
from2.textbox1.text= .Rows.Item(e.RowIndex).Cells(0).Value.ToString()
End With
End Sub 'เมื่อกดเลือกCellที่ต้องการข้อมูลจะไปที่ Textbox ของForm2 เเต่Form2 ต้องเปิดไว้ด้วยนะครับ ถ้าไม่เปิดไว้ก็ Share เอาก็ได้นะครับ
Imports System.Data.SqlClient
Public Class search
Dim Conn As SqlConnection = New SqlConnection
Dim ds As New DataSet
Dim da As SqlDataAdapter
Private Sub btnsearch_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsearch.Click
'If MsgBox("คุณต้องการค้นหาข้อมูลใช่หรือไม่ ?", MsgBoxStyle.Information + MsgBoxStyle.OkCancel, "ค้นหาข้อมูล") = MsgBoxResult.Ok Then
Try
ds.Tables.Clear()
Dim ra As String = ""
If RadioButton1.Checked Then
'Me.Label1.Text = "ตามรหัส"
ra = "LANDID"
End If
If RadioButton2.Checked Then
ra = "PARCEL_CODE"
End If
If TextBox4.Text = "" Then
MsgBox("กรุณากรอกข้อมูลที่ต้องการค้นหา", MsgBoxStyle.Information)
Else
Dim strConn As String
strConn = "Data Source=.\SQLEXPRESS;Initial Catalog=SSPEGIS;Integrated Security=True"
With Conn
If .State = ConnectionState.Open Then .Close() 'ถ้าเปิดอยู่ให้ปิดการเชื่อมต่อ Connection ก่อน
.ConnectionString = strConn ' กำหนดรูปแบบและฐานข้อมูลสำหรับการติดต่อ
.Open() 'ทำการติดต่อฐานข้อมูล
End With
Dim sql As String = "Select* from land WHERE " & ra & " like '" & TextBox4.Text & "%'"
da = New SqlDataAdapter(sql, Conn)
da.Fill(ds, "land")
myGridView.DataSource = ds.Tables("land")
TextBox4.Clear()
End If
' If dgv1.DataSource = "" Then
'MsgBox("iiii")
' End If
Catch ex As Exception
MessageBox.Show(ex.ToString, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
' End If
Dim cs As New DataGridViewCellStyle
cs.Font = New Font("ms sans serif", 10, FontStyle.Regular)
cs.Alignment = DataGridViewContentAlignment.MiddleCenter
cs.ForeColor = Color.Blue
With myGridView
.ColumnHeadersDefaultCellStyle = cs
.Columns(0).HeaderText = "ID"
.Columns(1).HeaderText = "รหัสภาษี"
.Columns(2).HeaderText = "รหัสเเผนที่"
.Columns(0).Width = 180
.Columns(1).Width = 140
.Columns(2).Width = 100
.Columns(0).SortMode = DataGridViewColumnSortMode.NotSortable
.Columns(1).SortMode = DataGridViewColumnSortMode.NotSortable
.Columns(2).SortMode = DataGridViewColumnSortMode.NotSortable
End With
End Sub
Private Sub dgv_CellMouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles myGridView.CellMouseUp
If e.RowIndex = -1 Then Exit Sub
With myGridView
frmland.txtLANDID.Text = .Rows.Item(e.RowIndex).Cells(0).Value.ToString()
frmland.txtPARCEL_CODE.Text = .Rows.Item(e.RowIndex).Cells(1).Value.ToString()
frmland.txtPICTURE_CODE.Text = .Rows.Item(e.RowIndex).Cells(2).Value.ToString()
frmland.txtUTM_CODE.Text = .Rows.Item(e.RowIndex).Cells(21).Value.ToString()
frmland.txtUTM_NO.Text = .Rows.Item(e.RowIndex).Cells(23).Value.ToString()
frmland.txtUTM_NO_P.Text = .Rows.Item(e.RowIndex).Cells(22).Value.ToString()
frmland.txtUTM_RATIO.Text = .Rows.Item(e.RowIndex).Cells(20).Value.ToString()
frmland.txtLDOC_NO.Text = .Rows.Item(e.RowIndex).Cells(19).Value.ToString()
frmland.txtTAXRATE.Text = .Rows.Item(e.RowIndex).Cells(39).Value.ToString()
frmland.txtEXTENUATE.Text = .Rows.Item(e.RowIndex).Cells(40).Value.ToString()
frmland.txtSURVEY_NO.Text = .Rows.Item(e.RowIndex).Cells(26).Value.ToString()
frmland.txtLAND_NO.Text = .Rows.Item(e.RowIndex).Cells(25).Value.ToString()
frmland.txtDOL_RAI.Text = .Rows.Item(e.RowIndex).Cells(27).Value.ToString()
frmland.txtDOL_NGAN.Text = .Rows.Item(e.RowIndex).Cells(28).Value.ToString()
frmland.txtDOL_WA.Text = .Rows.Item(e.RowIndex).Cells(29).Value.ToString()
frmland.txtTAXED_RAI.Text = .Rows.Item(e.RowIndex).Cells(39).Value.ToString()
frmland.txtTAXED_NGAN.Text = .Rows.Item(e.RowIndex).Cells(40).Value.ToString()
frmland.txtTAXED_WA.Text = .Rows.Item(e.RowIndex).Cells(41).Value.ToString()
frmland.txtTAMBON_TH.Text = .Rows.Item(e.RowIndex).Cells(16).Value.ToString()
frmland.txtDISTRICT_TH.Text = .Rows.Item(e.RowIndex).Cells(17).Value.ToString()
frmland.txtPROVINCE_TH.Text = .Rows.Item(e.RowIndex).Cells(18).Value.ToString()
Dim dt As New DataTable
Dim bin As New BindingSource
Dim sqlldoc_type As String = ""
sqlldoc_type = "SELECT land.LANDID, land.LDOC_TYPEID, ldoc_type.LDOC_TYPE FROM land LEFT JOIN ldoc_type ON land.LDOC_TYPEID = ldoc_type.LDOC_TYPEID "
da = New SqlDataAdapter(sqlldoc_type, Conn)
da.Fill(ds, "ldoc_type")
Dim cmd As SqlCommandBuilder
cmd = New SqlCommandBuilder(da)
bin.DataSource = dt
If frmland.cboLDOC_TYPE.Text = .Rows.Item(e.RowIndex).Cells(9).Value.ToString() Then
With frmland.cboLDOC_TYPE
.DisplayMember = "LDOC_TYPE"
.ValueMember = "LDOC_TYPEID"
.DataSource = ds.Tables("ldoc_type")
.DataBindings.Add("SelectedValue", bin, "LDOC_TYPEID")
End With
End If
Me.Close()
End With
End Sub
End Class