alsam
asked on
How to call cellPainting sub after cell value is changed in datagridview
Hi,
I use CellPainting to show column total in datagridview...
When I load my form totals are calculated OK...
After I change content of cell in datagridview I expect totals to be changed but unfortunatelly it does not happens....It's recalculated when I change for eg width of column where cell value is changed
How can I call cellPainting to recalculate totals after cell value is changed....
Please help
Thanks...
Code below...
I use CellPainting to show column total in datagridview...
When I load my form totals are calculated OK...
After I change content of cell in datagridview I expect totals to be changed but unfortunatelly it does not happens....It's recalculated when I change for eg width of column where cell value is changed
How can I call cellPainting to recalculate totals after cell value is changed....
Please help
Thanks...
Code below...
Public Sub DataGridView1_CellPainting(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles DataGridView1.CellPainting
Dim sum As Decimal = 0.0
If (e.RowIndex = DataGridView1.NewRowIndex And e.ColumnIndex > 1) Then
For i As Integer = 0 To DataGridView1.NewRowIndex - 1
If (DataGridView1.Rows(i).Cells(e.ColumnIndex).Value.ToString().Trim() <> "") Then
sum += Convert.ToDecimal(DataGridView1.Rows(i).Cells(e.ColumnIndex).Value)
End If
Next i
e.PaintBackground(e.CellBounds, False)
e.Graphics.DrawString(sum.ToString(), DataGridView1.Font,
Brushes.Black, e.CellBounds.Left + 2, e.CellBounds.Top + 2)
e.Handled = True
End If
End Sub
Try using the CellEndEdit event of the datagridview instead
ASKER
Hi,
thank you for your reply...
Errors are as follows:
'PaintBackground' is not member of System.Windows.Forms.DataG
'Handled' is not member of System.Windows.Forms.DataG
'Graphics' is not member of System.Windows.Forms.DataG
......
Do you have any other idea what should I do?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you very much...
It works with small adjustments...
It works with small adjustments...