VSTO - DataGRidView change line colour on click

Posted on 2011-05-11
Last Modified: 2012-05-11

In a DataGridView is it possible using code to change the row color,
Question by:murbro
    LVL 17

    Expert Comment

    handle the click event and set the row color by

    Dim MyGrid =DirectCast(Sender, DataGridView)

    Open in new window

    LVL 9

    Accepted Solution

    use this code after setting the datasource on DataGridView:-

    For Each dgvr As DataGridViewRow In myDGV.Rows
    	If dgvr.Cells(0).Value < dgvr.Cells(1).Value Then    ' You may have some other condition
    		dgvr.DefaultCellStyle.ForeColor = Color.Red
                    dgvr.DefaultCellStyle.BackColor = Color.Yellow
    	End If

    Open in new window

    LVL 9

    Expert Comment

    here myDGV is the ID of the DataGridView

    Author Closing Comment

    thanks very much

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Suggested Solutions

    Article by: jpaulino
    XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String ( Literal, only instead of starting and ending with w…
    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.
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    758 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

    10 Experts available now in Live!

    Get 1:1 Help Now