gp1619 โพสต์ 2019-8-1 13:44:42

ตรวจสอบการป้อนข้อมูลใน DataGridview หากเหตุการณ์ แบบที่ 5 เป็นจริงให้แสดงข้อความแจ้งเตือน




thongkorn โพสต์ 2019-8-3 12:38:56

ไม่ได้บอกรายละเอียดมาว่าต้องเกิดเหตุการณ์ตรวจสอบตอนไหน ผมขอตอบแบบรวมๆของ 5 แบบก็แล้วกันครับ ...
    '// เผื่อนำค่าไปใช้งาน
    Dim blnKeyPress As Boolean() = {False, False, False, False}

    Private Sub CheckData()
      '// แถว 0, หลัก 0 (อ่านค่าตาม Index โดยเริ่มจากแถว 0, หลัก 0)
      If DataGridView1.Rows(0).Cells(0).Value <> "" Then
            blnKeyPress(0) = True
            MsgBox("คุณคีย์ข้อมูลแถว 0, หลัก 0")
      End If
      '// แถว 1 หลัก 0
      If DataGridView1.Rows(1).Cells(0).Value <> "" Then
            blnKeyPress(1) = True
            MsgBox("คุณคีย์ข้อมูลแถว 1, หลัก 0")
      End If
      '// แถว 2 หลัก 1
      If DataGridView1.Rows(2).Cells(1).Value <> "" Then
            blnKeyPress(2) = True
            MsgBox("คุณคีย์ข้อมูลแถว 2, หลัก 1")
      End If
      '// แถว 3 หลัก 1
      If DataGridView1.Rows(3).Cells(1).Value <> "" Then
            blnKeyPress(3) = True
            MsgBox("คุณคีย์ข้อมูลแถว 3, หลัก 1")
      End If
    End Sub

gp1619 โพสต์ 2019-8-5 15:12:58

CellEndEdit ครับ

gp1619 โพสต์ 2019-8-5 16:43:13

แก้ไขครั้งสุดท้ายโดย gp1619 เมื่อ 2019-8-9 09:45

ขอบคุณครับ อาจารย์
      

thongkorn โพสต์ 2019-8-6 12:35:20

ผมก็ไม่รู้ว่าจะใช่ตามที่ต้องการหรือเปล่าน่ะครับ ...
    Dim blnKeyPress As Boolean() = {False, False, False, False}

    Function ValidData() As Boolean
      '// Reset
      blnKeyPress = {False, False, False, False}
      '// Initialize
      ValidData = False
      '// แถว 0, หลัก 0 (อ่านค่าตาม Index)
      If DataGridView1.Rows(0).Cells(0).Value <> "" Then
            blnKeyPress(0) = True
      End If
      '// แถว 1 หลัก 0
      If DataGridView1.Rows(1).Cells(0).Value <> "" Then
            blnKeyPress(1) = True
      End If
      '// แถว 2 หลัก 1
      If DataGridView1.Rows(2).Cells(1).Value <> "" Then
            blnKeyPress(2) = True
      End If
      '// แถว 3 หลัก 1
      If DataGridView1.Rows(3).Cells(1).Value <> "" Then
            blnKeyPress(3) = True
      End If
      '// ตรวจสอบและคืนค่า
      If blnKeyPress(0) And blnKeyPress(1) And blnKeyPress(2) And blnKeyPress(3) Then ValidData = True

    End Function

    Private Sub DataGridView1_CellEndEdit(sender As Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit
      If ValidData() Then
            MsgBox("Have data in cell 1, 2, 3 and 4.")
      End If
    End Sub

gp1619 โพสต์ 2019-8-6 15:56:36

ขอบคุณมาก ครับ
หน้า: [1]
ดูในรูปแบบกติ: ตรวจสอบการป้อนข้อมูลใน DataGridview หากเหตุการณ์ แบบที่ 5 เป็นจริงให้แสดงข้อความแจ้งเตือน