Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


DataGridView - Automatically scrolls to top of grid on mouse click

DataGridView - Automatically scrolls to top of grid on mouse click

DataGridView - Automatically scrolls to top of grid on mouse click

I have a real strange problem with a DataGridView in a windows form programming in vb.net in VS 2015 Professional.

It centers around what happens with the clicking of a cell in a row. Most of the time, doing so results in the row being selected and its position in the grid remaining as it is without the DataGridView doing any scrolling. But some times (maybe as much as 50% of the time), clicking the cell results in very strange behavior.
1. The row is selected.
2. The DataGridView scrolls up to the first row of the grid. I can then scroll down to the row I clicked on and it is selected.
3. The MouseClick event fires.
4. The CellClick event doesn't fire.

The big question is, "What the heck is going on?". How can a row get selected without the CellClick event firing? And what makes the thing scroll to the top of the grid???

This really screws up the users!!

As a workaround, I am doing a very klugey thing. I have a Boolean flgGotCellClick that only gets set to True in the CellClick event. I monitor that flag in the MouseClick event and if it is false, I retrieve the CurrentCell.rowIndex of the grid and set the FirstDisplayedScrollingRowIndex property to it. It then clears the flag. That is klugey because the end result is the just-selected row becomes visible at the top of the grid. While that is better than going all the way to the top of the grid, it's still a bad behavior.

I've tried setting the SelectionMode property to CellSelect, FullRowSelect, and RowHeaderSelect and it doesn't matter.

Does anyone have a fix for this?

Thanks in advance,

Jerry Scannell

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close