If you want to highlit datagridview row on mouse hover this tutorial is for you.
highlight datagridview row color on mouse hover C#.
you can learn how to change gridview row color on mouse hover using vb. how to highlight gridview row color dynamically in C#.
This tutorial also covered highlight datagridview row back color and datagridview row fore color with code in C# and This tutorial also covered highlight datagridview cell back color and gridview cell fore color with code in C# windows form application.
Write code in gridview row mouse move event and row mouse leave event. finally change backcolor of datagridview and cell color in vb.net dynamically. for example when you move mouse or stay on a row that row will be highlighted.
Output:
Youtube:
C# Code:
Person.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace FormExample12 { class Person { string name; string lastname; int age; public Person(string name, string lastname, int age) { this.name = name; this.lastname = lastname; this.age = age; } public string Name { get => name; set => name = value; } public string Lastname { get => lastname; set => lastname = value; } public int Age { get => age; set => age = value; } } } |
Form.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace FormExample12 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } List<Person> list; private void button1_Click(object sender, EventArgs e) { list = new List<Person>(); list.Add(new Person("Henry", "Johan", 40)); list.Add(new Person("Jacob", "Wilson", 25)); list.Add(new Person("Jack", "Lopez", 25)); list.Add(new Person("Levi", "Lee", 40)); list.Add(new Person("Mateo", "Davis", 23)); list.Add(new Person("Martin", "Lunge", 38)); dataGridView1.DataSource = list; } private void dataGridView1_CellMouseMove(object sender, DataGridViewCellMouseEventArgs e) { DataGridViewCellStyle style1 = new DataGridViewCellStyle(); style1.ForeColor = Color.Azure; style1.BackColor = Color.Crimson; if (e.RowIndex > -1) dataGridView1.Rows[e.RowIndex].DefaultCellStyle = style1; } private void dataGridView1_CellMouseLeave(object sender, DataGridViewCellEventArgs e) { DataGridViewCellStyle style2 = new DataGridViewCellStyle(); style2.ForeColor = Color.Black; style2.BackColor = Color.WhiteSmoke; if (e.RowIndex > -1) dataGridView1.Rows[e.RowIndex].DefaultCellStyle = style2; } } } |