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....
amaimediaAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Bob LearnedConnect With a Mentor Commented:
With the DataGridView, you can handle the CellFormatting event handler to check values, and set cell styles.

Bob
0
 
iboutchkineCommented:
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
0
 
Bob LearnedCommented:
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
0
 
planoczCommented:

Check this link to see if this is want you are looking for...
http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_22477105.html
0
 
amaimediaAuthor Commented:
This solutions doesn't work in my case....
I fill this datagrid view from datatable
0
All Courses

From novice to tech pro — start learning today.