回答編集履歴

4

Overideの実装例を追記

2018/01/03 12:43

投稿

sheephuman
sheephuman

スコア112

test CHANGED
@@ -1,3 +1,47 @@
1
+ OnMouseWheelをOverRideしたときの実装
2
+
3
+
4
+
5
+  ```ここに言語を入力
6
+
7
+ {
8
+
9
+ protected override void OnMouseWheel(MouseEventArgs e)
10
+
11
+ {
12
+
13
+ try
14
+
15
+ {
16
+
17
+ HandledMouseEventArgs wEventArgs = e as HandledMouseEventArgs;
18
+
19
+ wEventArgs.Handled = true;
20
+
21
+
22
+
23
+ int Wheel = e.Delta / 120;
24
+
25
+ CurrentCell = Rows[CurrentCell.RowIndex -Wheel].Cells[0];
26
+
27
+ catch
28
+
29
+ { }
30
+
31
+ }
32
+
33
+
34
+
35
+ ```
36
+
37
+  とてもスムーズに動きました。助かりました。
38
+
39
+  随分と手間どってしまいました。 
40
+
41
+
42
+
43
+
44
+
1
45
  追記 スクロールイベントで調整したら意外と上手く行きました。
2
46
 
3
47
  ```ここに言語を入力

3

自己解決。

2018/01/03 12:43

投稿

sheephuman
sheephuman

スコア112

test CHANGED
@@ -1,3 +1,65 @@
1
+ 追記 スクロールイベントで調整したら意外と上手く行きました。
2
+
3
+ ```ここに言語を入力
4
+
5
+ private void dataGridView1_Scroll(object sender, ScrollEventArgs e)
6
+
7
+ {
8
+
9
+ int CurrentRow = dataGridView1.CurrentCell.RowIndex;
10
+
11
+
12
+
13
+ Text = CurrentRow.ToString();
14
+
15
+ if (dataGridView1.FirstDisplayedScrollingRowIndex < 10)
16
+
17
+ {
18
+
19
+
20
+
21
+ if (CurrentRow < 10)
22
+
23
+ {
24
+
25
+ dataGridView1.FirstDisplayedScrollingRowIndex = 0;
26
+
27
+ }
28
+
29
+ }
30
+
31
+ else if(dataGridView1.FirstDisplayedScrollingRowIndex >10)
32
+
33
+ {
34
+
35
+ if(CurrentRow > 10)
36
+
37
+ {
38
+
39
+
40
+
41
+ dataGridView1.FirstDisplayedScrollingRowIndex = CurrentRow-3;
42
+
43
+
44
+
45
+ }
46
+
47
+
48
+
49
+
50
+
51
+ }
52
+
53
+ }
54
+
55
+ ```
56
+
57
+
58
+
59
+
60
+
61
+
62
+
1
63
  結局、このような感じで調整しました。もっと良い方法があればお願いします。挙動が微妙です。
2
64
 
3
65
 

2

インデント調整

2018/01/03 11:36

投稿

sheephuman
sheephuman

スコア112

test CHANGED
@@ -6,25 +6,21 @@
6
6
 
7
7
  if (3 < CurrentRow && wheel == -1) //ホイール下移動時
8
8
 
9
- {
9
+ {
10
+
11
+ dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.CurrentCell.RowIndex-3 ;
12
+
13
+    }
10
14
 
11
15
 
12
16
 
13
- dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.CurrentCell.RowIndex-3 ;
17
+   else if(wheel == 1)  //ホイール上移動時
14
18
 
15
- }
19
+     {
16
20
 
17
- else if(wheel == 1)  //ホイール上移動時
21
+ dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.CurrentCell.RowIndex-6;
18
22
 
19
- {
20
-
21
-
22
-
23
- dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.CurrentCell.RowIndex-6;
24
-
25
-
26
-
27
- }
23
+    }
28
24
 
29
25
 
30
26
 

1

コメントアウト

2018/01/03 11:07

投稿

sheephuman
sheephuman

スコア112

test CHANGED
@@ -1,10 +1,10 @@
1
- 結局、このような感じで調整しました。もっと良い方法があればお願いします。
1
+ 結局、このような感じで調整しました。もっと良い方法があればお願いします。挙動が微妙です。
2
2
 
3
3
 
4
4
 
5
5
  ```
6
6
 
7
- if (3 < CurrentRow && wheel == -1)
7
+ if (3 < CurrentRow && wheel == -1) //ホイール下移動時
8
8
 
9
9
  {
10
10
 
@@ -14,7 +14,7 @@
14
14
 
15
15
  }
16
16
 
17
- else if(wheel == 1)
17
+ else if(wheel == 1)  //ホイール上移動時
18
18
 
19
19
  {
20
20