none
[C#]datagridview change backcolor on mouse over

    Question

  • Hi all Smile

    I would like to know how change backcolor(or have a kind of select) of an entire row when mouse pointer is on the row without the use of a mouse click.

    I mean something like:

    datagridview.CurrentRow.HighLight = true;


    Tuesday, April 10, 2007 9:38 AM

Answers

  • Code Snippet

            int OldRow = 0;

            private void dataGridView1_MouseMove(object sender, MouseEventArgs e)
            {
                DataGridView.HitTestInfo hti = dataGridView1.HitTest(e.X, e.Y);

                if (hti.RowIndex >= 0 && hti.RowIndex != OldRow)
                {
                    dataGridView1.Rows[OldRow].Selected = false;
                    dataGridView1.Rows[hti.RowIndex].Selected = true;
                    OldRow = hti.RowIndex;
                }
            }

     

     

    Tuesday, April 10, 2007 11:18 AM

All replies

  • Simply subscribe to the RowEnter and RowLeave events and do your thing Wink
    Tuesday, April 10, 2007 10:55 AM
  • Code Snippet

            int OldRow = 0;

            private void dataGridView1_MouseMove(object sender, MouseEventArgs e)
            {
                DataGridView.HitTestInfo hti = dataGridView1.HitTest(e.X, e.Y);

                if (hti.RowIndex >= 0 && hti.RowIndex != OldRow)
                {
                    dataGridView1.Rows[OldRow].Selected = false;
                    dataGridView1.Rows[hti.RowIndex].Selected = true;
                    OldRow = hti.RowIndex;
                }
            }

     

     

    Tuesday, April 10, 2007 11:18 AM
  • Great!!! Smile

    Many thx !
    Tuesday, April 10, 2007 2:04 PM