How to run Run CellEndEdit only when Cell ValueChanged in DataGridView

后端 未结 5 1284
囚心锁ツ
囚心锁ツ 2021-01-13 04:45

i want to run CellEndEdit only when value of cell is changed, tried putting

if (dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString() == e.For         


        
5条回答
  •  -上瘾入骨i
    2021-01-13 05:06

    I made it like so:

    C#:

    private void DynList_RowValidated(object sender, DataGridViewCellEventArgs e)
    {
        if (ChangedRow == true) {
            ChangedRow = false;
            //Row Changed...
        }
    
    }
    bool ChangedRow;
    private void DynList_CellValueChanged(object sender, DataGridViewCellEventArgs e)
    {
        ChangedRow = true;
    }
    

    VB.Net:

     Private Sub DynList_RowValidated(ByVal sender As Object, ByVal e As DataGridViewCellEventArgs)
            If ChangedRow = True Then
                ChangedRow = False
                'Row Changed...
            End If
    
     End Sub
     Dim ChangedRow As Boolean
     Private Sub DynList_CellValueChanged(ByVal sender As Object, ByVal e As DataGridViewCellEventArgs)
            ChangedRow = True
     End Sub
    

    I tried like 1 hour to archieve this, because no one had a solution for that, so I thought it might be useful for others

提交回复
热议问题