vendredi 13 mars 2015

Change specific row and column in Datagridview

I want to change specific row and column in Datagridview. when I enter specific data in column x it will return any specific value in column Y. Otherwise data in column x will return value 7777 in column Y


enter image description here


But when I run this code, there were nothing change in column Y :



Private Sub Table1DataGridView_CellEndEdit(sender As Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles Table1DataGridView.CellEndEdit

'For e.ColumnIndex + 1
If e.ColumnIndex = 2 Then
If Val(Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex).Value) = 5 Then
Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = 5

ElseIf Val(Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex).Value) = 7 Then
Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = 7

ElseIf Val(Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex).Value) = 1 Then
Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = 6
'1
ElseIf Val(Table1DataGridView.Rows(1).Cells(2).Value) = 1.5 Then
Table1DataGridView.Rows(1).Cells(e.ColumnIndex + 1).Value = 7.326
'2
ElseIf Val(Table1DataGridView.Rows(2).Cells(2).Value) = 2 Then
Table1DataGridView.Rows(2).Cells(e.ColumnIndex + 1).Value = 6.374
'3
ElseIf Val(Table1DataGridView.Rows(3).Cells(2).Value) = 2.5 Then
Table1DataGridView.Rows(3).Cells(e.ColumnIndex + 1).Value = 4.702
'4
ElseIf Val(Table1DataGridView.Rows(4).Cells(2).Value) = 2 Then
Table1DataGridView.Rows(4).Cells(e.ColumnIndex + 1).Value = 1.321
'5
ElseIf Val(Table1DataGridView.Rows(5).Cells(2).Value) = 2.5 Then
Table1DataGridView.Rows(5).Cells(e.ColumnIndex + 1).Value = 0.035
'6
ElseIf Val(Table1DataGridView.Rows(6).Cells(2).Value) = 4 Then
Table1DataGridView.Rows(6).Cells(e.ColumnIndex + 1).Value = 0.205
'7
ElseIf Val(Table1DataGridView.Rows(7).Cells(2).Value) = 2.5 Then
Table1DataGridView.Rows(7).Cells(e.ColumnIndex + 1).Value = 4.969
'8
ElseIf Val(Table1DataGridView.Rows(16).Cells(2).Value) = 4 Then
Table1DataGridView.Rows(16).Cells(e.ColumnIndex + 1).Value = 1.588
'9
ElseIf Val(Table1DataGridView.Rows(17).Cells(2).Value) = 2.5 Then
Table1DataGridView.Rows(17).Cells(e.ColumnIndex + 1).Value = 4.696
'10
ElseIf Val(Table1DataGridView.Rows(18).Cells(2).Value) = 2.5 Then
Table1DataGridView.Rows(18).Cells(e.ColumnIndex + 1).Value = 0.866
'11
ElseIf Val(Table1DataGridView.Rows(19).Cells(2).Value) = 2 Then
Table1DataGridView.Rows(19).Cells(e.ColumnIndex + 1).Value = 1.881
'12
ElseIf Val(Table1DataGridView.Rows(20).Cells(2).Value) = 2.5 Then
Table1DataGridView.Rows(20).Cells(e.ColumnIndex + 1).Value = 4.702
'13
ElseIf Val(Table1DataGridView.Rows(21).Cells(2).Value) = 2 Then
Table1DataGridView.Rows(21).Cells(e.ColumnIndex + 1).Value = 6.515
'14
ElseIf Val(Table1DataGridView.Rows(22).Cells(2).Value) = 1.5 Then
Table1DataGridView.Rows(22).Cells(e.ColumnIndex + 1).Value = 6.92671744
Else
Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = 7777

End If
End If

End Sub


Then, I try to change this code, but return some same value at column Y :



Private Sub Table1DataGridView_CellEndEdit(sender As Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles Table1DataGridView.CellEndEdit

'For e.ColumnIndex + 1
If e.ColumnIndex = 2 Then
If Val(Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex).Value) = 5 Then
Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = 5

ElseIf Val(Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex).Value) = 7 Then
Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = 7

ElseIf Val(Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex).Value) = 1 Then
Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = 6
'1
ElseIf Val(Table1DataGridView.Rows(1).Cells(2).Value) = 1.5 Then
Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = 7.326
'2
ElseIf Val(Table1DataGridView.Rows(2).Cells(2).Value) = 2 Then
Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = 6.374
'3
ElseIf Val(Table1DataGridView.Rows(3).Cells(2).Value) = 2.5 Then
Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = 4.702
'4
ElseIf Val(Table1DataGridView.Rows(4).Cells(2).Value) = 2 Then
Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = 1.321
'5
ElseIf Val(Table1DataGridView.Rows(5).Cells(2).Value) = 2.5 Then
Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = 0.035
'6
ElseIf Val(Table1DataGridView.Rows(6).Cells(2).Value) = 4 Then
Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = 0.205
'7
ElseIf Val(Table1DataGridView.Rows(7).Cells(2).Value) = 2.5 Then
Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = 4.969
'8
ElseIf Val(Table1DataGridView.Rows(16).Cells(2).Value) = 4 Then
Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = 1.588
'9
ElseIf Val(Table1DataGridView.Rows(17).Cells(2).Value) = 2.5 Then
Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = 4.696
'10
ElseIf Val(Table1DataGridView.Rows(18).Cells(2).Value) = 2.5 Then
Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = 0.866
'11
ElseIf Val(Table1DataGridView.Rows(19).Cells(2).Value) = 2 Then
Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = 1.881
'12
ElseIf Val(Table1DataGridView.Rows(20).Cells(2).Value) = 2.5 Then
Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = 4.702
'13
ElseIf Val(Table1DataGridView.Rows(21).Cells(2).Value) = 2 Then
Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = 6.515
'14
ElseIf Val(Table1DataGridView.Rows(22).Cells(2).Value) = 1.5 Then
Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = 6.92671744
Else
Table1DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value = 7777

End If
End If

End Sub


Thanks for the help!


Aucun commentaire:

Enregistrer un commentaire