?
Solved

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

Posted on 2013-10-30
3
Medium Priority
?
1,084 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 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

800 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