Solved

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

Posted on 2013-10-30
3
1,025 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 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

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…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

823 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