Link to home
Start Free TrialLog in
Avatar of amaimedia
amaimediaFlag for Bosnia and Herzegovina

asked on

Datagrid view another colors

VB.net

Hi experts

How can I mark negative values in columns of datagrid view with other colors? The Columns are type of integer....
Avatar of iboutchkine
iboutchkine

on Validating
 dgv.Rows(e.RowIndex).Cells(e.ColumnIndex).Style.BackColor = Color.Red

example

 Private Sub dgv_CellValidating(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles dgv.CellValidating

        ' Don't try to validate the 'new row' until finished
        ' editing since there
        ' is not any point in validating its initial value.
        If dgv.Rows(e.RowIndex).IsNewRow Then Return
       
        'add validation that value in the cell is numeric
        If IsNumeric(e.FormattedValue) Then
         'check condition
         If e.FormattedValue < 0 Then
              dgv.Rows(e.RowIndex).Cells(e.ColumnIndex).Style.BackColor = Color.Red
         End If
        End If
Avatar of Bob Learned
Why do we always have to make assumptions about data grid type?  That is code for a WinForms DataGridView, but there is the 1.1 ASP.NET DataGrid, ASP.NET 2.0 GridView, and the plain ol' WinForms DataGrid for both 1.1 and 2.0.

Bob
Avatar of amaimedia

ASKER

This solutions doesn't work in my case....
I fill this datagrid view from datatable
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America 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