nnnn
nnnn

Reputation: 1051

Handling Mouse Scroll event of window datagrid in C#

Can anybody tell me how to handle mouse scroll event(vertical scroll) in a datagrid? If i scroll the mouse scroller, then datagrid will scrolls. I want to get rowIndex of datagrid's row that is displayed at the top when scroll the grid vertically.

can any body help me?

Upvotes: 2

Views: 2890

Answers (3)

Javed Akram
Javed Akram

Reputation: 15344

Use DataGridView Scroll event

 if (e.ScrollOrientation == ScrollOrientation.VerticalScroll)
 {
      int i = dataGridView1.FirstDisplayedCell.RowIndex;
 }

Upvotes: 1

Hans Passant
Hans Passant

Reputation: 941327

Use the FirstDisplayedScrollingRowIndex property.

Upvotes: 2

Machinarius
Machinarius

Reputation: 3731

You can use MouseWheel and/or PreviewMouseWheel events of the DataGrid MouseWheel fires when the user ended scrolling, whilst the Preview one fires when the user is about to scroll

Concerning the topmodt drawn index, i cant say anything :/

Hope it helps :p

Upvotes: 0

Related Questions