• 쇼핑몰
  • 커뮤니티
  • 북마크

vb.net


[Controls] [vb.net] DataGridView의 CellValidating 이벤트를 활용한 셀 변경 값, 변경 이전 값을 비교하여 이…

하나를하더라도최선을
2021.08.17 07:48 130 0

본문



    Private Sub DataGridView_CellValidating(sender As Object, e As DataGridViewCellValidatingEventArgs) Handles DataGridView1.CellValidating,
                                                                                                            DataGridView2.CellValidating,
                                                                                                            DataGridView4.CellValidating,
                                                                                                            DataGridView5.CellValidating,
                                                                                                            DataGridView7.CellValidating
 
        If e.ColumnIndex < 0 Then Return
        If e.RowIndex < 0 Then Return
        Dim DGV As DataGridView = CType(sender, DataGridView)
        If DGV.Rows.Count = 0 Then Return
        Dim key As String = DGV.Columns(e.ColumnIndex).Name
        If key = "ck" Then DGV.EndEdit() : Return
        Dim URL As String, PostData As String, T As String
        Dim R As DataGridViewRow = DGV.Rows(e.RowIndex)
        Dim cell As DataGridViewTextBoxCell = R.Cells(key)
        Dim oldValue As String, newValue As String
 
        If IsDBNull(cell.Value) Then Return
        oldValue = cell.Value
        newValue = e.FormattedValue
        If oldValue = newValue Then Return
 
        If key = "note" Then
            '// 원하는 작업
        Else
            e.Cancel = True
            If cell.IsInEditMode Then DGV.EndEdit()
            cell.Value = oldValue
        End If
    End Sub
 


댓글목록 0

등록된 댓글이 없습니다.