Solved

Help with changing row colour on mouse move event using VB.NET

Posted on 2013-10-30
3
984 Views
Last Modified: 2013-10-30
Ho do you change the backcolor and text forecolor of a row when you place the mouse over it?

I am using the DataGridView that comes with VS2010.

Thanks,

Victor
0
Comment
Question by:vcharles
  • 2
3 Comments
 
LVL 25

Accepted Solution

by:
Shaun Kline earned 500 total points
Comment Utility
You can use the CellMouseEnter event to handle the mouse entering a cell in a row, and the CellMouseLeave event to handle the mouse leaving a cell in a row. The code would look like: (GridViewName should be replaced with the name of your DataGridView.)

    Private Sub GridViewName_CellMouseEnter(sender As Object, e As DataGridViewCellEventArgs) Handles GridViewName.CellMouseEnter
        If e.ColumnIndex > 0 AndAlso e.RowIndex > 0 Then
            GridViewName.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.DarkBlue
            GridViewName.Rows(e.RowIndex).DefaultCellStyle.ForeColor = Color.BlanchedAlmond
            GridViewName.Rows(e.RowIndex).DefaultCellStyle.Font = _
                New Font(GridViewName.DefaultCellStyle.Font.FontFamily, _
                         GridViewName.DefaultCellStyle.Font.Size, FontStyle.Bold)
        End If
    End Sub

    Private Sub GridViewName_CellMouseLeave(sender As Object, e As DataGridViewCellEventArgs) Handles GridViewName.CellMouseLeave
        If e.ColumnIndex > 0 AndAlso e.RowIndex > 0 Then
            GridViewName.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.White
            GridViewName.Rows(e.RowIndex).DefaultCellStyle.ForeColor = Color.Black
            GridViewName.Rows(e.RowIndex).DefaultCellStyle.Font = _
                New Font(GridViewName.DefaultCellStyle.Font.FontFamily, _
                         GridViewName.DefaultCellStyle.Font.Size, FontStyle.Regular)
        End If
    End Sub

Open in new window

0
 

Author Comment

by:vcharles
Comment Utility
Thanks, will try it and get back toy you.
0
 

Author Closing Comment

by:vcharles
Comment Utility
Thank You!
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
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.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

728 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

12 Experts available now in Live!

Get 1:1 Help Now