[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

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

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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

656 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