Setting the back brush color of a grid cell to a color picked from a color dialog control

Posted on 2006-04-07
Last Modified: 2012-05-05

I am trying to set the background color of individual cells in a grid to different colors that have been selected from a color dialog control.

For a test I selected a color from a color dialog control and saved it to an integer variable as follows:

colorArgb  = Me.Label1.ForeColor.ToArgb

The test form contains a grid and I have the following subroutines to format the grid cells:

 AddCellFormattingColumnStyles(Me.grdColorcodes, New FormatCellEventHandler(AddressOf FormatGridCells))
    Private Sub AddCellFormattingColumnStyles(ByVal grid As DataGrid, ByVal handler As FormatCellEventHandler)

        Dim ts As DataGridTableStyle
        ts = New DataGridTableStyle
        Dim dt As DataView
        dt = CType(grid.DataSource, DataView)
        ts.MappingName = "codetable"

    Private Sub FormatGridCells(ByVal sender As Object, ByVal e As DataGridFormatCellEventArgs)
        If e.row = 4 and e.Column = 3 Then
             e.BackBrush = Color.FromArgb(colorArgb)
        End If

The problem is that the statement  'e.BackBrush = Color.FromArgb(colorArgb)' is invalid and I get the error message "Value of "System.Drawing.Color" cannot be converted to 'System.Drawing.Brush'".

Can I some how use the value in the variable 'colorArgb' to set the color of a specific grid cell or is there another way to do so?

Thanks in advance

Question by:laschwabe
    1 Comment
    LVL 4

    Accepted Solution

    blackbrush = new solidbrush(color.fromargb(colorargb))

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Introduction When many people think of the WebBrowser ( control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
    Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    759 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