Solved

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

Posted on 2013-10-30
3
1,067 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 26

Accepted Solution

by:
Shaun Kline earned 500 total points
ID: 39611441
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
ID: 39611456
Thanks, will try it and get back toy you.
0
 

Author Closing Comment

by:vcharles
ID: 39611480
Thank You!
0

Featured Post

Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
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.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

691 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