1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
Public Class Form2
Private table As DataTable = Nothing
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
table = GetTable()
Me.DataGridView1.DataSource = table
Dim nokColumn As New DataGridViewTextBoxColumn()
nokColumn.Name = "Realise"
nokColumn.HeaderText = "Realise"
nokColumn.ValueType = GetType(String)
Me.DataGridView1.Columns.Insert(0, nokColumn)
InitializeNok()
End Sub
Private Function GetTable() As DataTable
Dim table As New DataTable("Types")
table.Columns.Add(New DataColumn("Type1", GetType(String)))
table.Columns.Add(New DataColumn("Salaire", GetType(Decimal)))
AddRowToTable(table, "CO", 2500.0)
AddRowToTable(table, Nothing, 4200.0)
AddRowToTable(table, Nothing, 3255.4)
AddRowToTable(table, "CO", 1254.3)
Return table
End Function
Private Sub AddRowToTable(ByVal dt As DataTable, ByVal itemType As String, ByVal itemSalaire As Decimal)
Dim dr As DataRow = dt.NewRow()
dr(0) = itemType
dr(1) = itemSalaire
dt.Rows.Add(dr)
End Sub
Private Sub InitializeNok()
For i As Integer = 0 To Me.DataGridView1.RowCount - 1
Dim drv As DataGridViewRow = Me.DataGridView1.Rows(i)
UpdatCellNok(drv)
Next
End Sub
Private Sub DataGridView1_CellEndEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit
Dim drv As DataGridViewRow = Me.DataGridView1.CurrentRow
UpdatCellNok(drv)
End Sub
'la sub qui fait la maj de la cellule "Realise"
Private Sub UpdatCellNok(ByVal drv As DataGridViewRow)
Dim a As Object = drv.Cells("Type1").Value
Dim aValue As String = Nothing
Dim nokString As String = Nothing
If (a IsNot Nothing) Then
aValue = a.ToString
End If
If aValue = "CO" Then
nokString = "OK"
Else
nokString = "NOK"
End If
drv.Cells("Realise").Value = nokString
End Sub
End Class |
Partager