Imports System.Data
Imports System.Data.OleDb
Public Class ShowCus
    Dim gsql As String
    Dim cmd As New OleDbCommand
    Dim dr As OleDbDataReader
    Private Sub ShowCus_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ConnectDatabase()
        showlist()
        SetGrid()
        SetHeaderGrid()
    End Sub

    Private Sub showlist() 'dataGridView
        Dim dt As New DataTable
        gsql = "select M_ID,M_Name from MEMBER"
        With cmd
            .CommandType = CommandType.Text
            .CommandText = gsql
            .Connection = cnn
            dr = .ExecuteReader
        End With
        If dr.HasRows Then
            dt.Load(dr)
            DataGridView1.DataSource = dt 'dtโหลด dr ให้ dgv=dt
        End If
        dr.Close()
    End Sub
    Private Sub SetHeaderGrid()
        'datagrid
        If DataGridView1.RowCount > 0 Then
            DataGridView1.Columns(0).HeaderText = "รหัสสมาชิก"
            DataGridView1.Columns(0).Width = 100
            DataGridView1.Columns(1).HeaderText = "ชื่อสมาชิก"
            DataGridView1.Columns(1).Width = 300
        End If
    End Sub
    Private Sub SetGrid() 'สร้างข้อความหัวคอลัมน์ แก้ไขหัวคอลัมน์ตามต้องการ

        If DataGridView1.Columns(0).HeaderText = "รหัสสมาชิก" Then
            DataGridView1.Columns(0).Width = 100
            DataGridView1.Columns(1).HeaderText = "ชื่อสมาชิก"
            DataGridView1.Columns(1).Width = 300

        End If
    End Sub

    Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
        Dim i As Integer 'ดับเบิ้ลคลิก
        With DataGridView1
            If e.RowIndex >= 0 Then
                i = .CurrentRow.Index
                FmSale.txtCusNo.Text = .Rows(i).Cells(0).Value.ToString
                FmSale.lblCus_Name.Text = .Rows(i).Cells(1).Value.ToString

            End If
        End With
        Me.Close()
    End Sub
End Class