Link to home
Start Free TrialLog in
Avatar of franklinan
franklinan

asked on

URGENT :DataGridView: Update cell content (cell_1) when editing Cell_2, and viceversa.

Hello Experts :

I want to do the following :

I have a datagridview with manual bind to Db, and there are two columns that can be modified. My problem is that I want to update the column_one if column_Two is modified, and I want to update column_Two if user is editing column_one. How to do this ? I ve tried this code and doesnt works :

Private Sub DGridView_CellValueChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGridView.CellValueChanged
        Dim NomTaula As String = "T_Linies" & Calendari.SelectionRange.Start.Year.ToString

        If e.RowIndex <> -1 Then
            Select Case e.ColumnIndex
               
                Case 1   'column_one
                   
                    If IsNumeric(DGridView.CurrentCell.Value) Then
                        DGridView.CurrentRow.Cells(2).Value = Math.Round((Integer.Parse(DGridView.CurrentRow.Cells(1).Value, Globalization.NumberStyles.Integer) * 100) / DGridView.CurrentRow.Cells(3).Value, 0)
                    End If
                Case 2   ' Column_two

                    If IsNumeric(Integer.Parse(DGridView.CurrentCell.Value, Globalization.NumberStyles.Integer)) Then 'And DGridView.CurrentCell.Style.BackColor = Color.Orange Then
                        DGridView.CurrentRow.Cells(1).Value = Math.Round((CInt(DGridView.CurrentRow.Cells(3).Value) * CInt(DGridView.CurrentRow.Cells(5).Value)) / 100, 0)
                    End If
            End Select
        End If

    End Sub


This code DOES NOT works because the application enters on a bucle, if I modify the column_one, the column_two is updated but the event is fiered again (because column_one has been modifed...)


Any idea please ?  ?
ASKER CERTIFIED SOLUTION
Avatar of Praveen Kumar
Praveen Kumar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of franklinan
franklinan

ASKER

Thnaks a lot !! Sorry for my delay in answer...Great !