Datagrid view another colors

Posted on 2007-10-19
Last Modified: 2008-01-09

Hi experts

How can I mark negative values in columns of datagrid view with other colors? The Columns are type of integer....
Question by:amaimedia
    LVL 28

    Expert Comment

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


     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
    LVL 96

    Expert Comment

    by: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.

    LVL 27

    Expert Comment


    Check this link to see if this is want you are looking for...

    Author Comment

    This solutions doesn't work in my case....
    I fill this datagrid view from datatable
    LVL 96

    Accepted Solution

    With the DataGridView, you can handle the CellFormatting event handler to check values, and set cell styles.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now