質問編集履歴
3
コードを削除
test
CHANGED
File without changes
|
test
CHANGED
@@ -18,190 +18,6 @@
|
|
18
18
|
|
19
19
|
|
20
20
|
|
21
|
-
###該当のソースコード
|
22
|
-
|
23
|
-
```C#
|
24
|
-
|
25
|
-
using System;
|
26
|
-
|
27
|
-
using System.Collections.Generic;
|
28
|
-
|
29
|
-
using System.ComponentModel;
|
30
|
-
|
31
|
-
using System.Data;
|
32
|
-
|
33
|
-
using System.Drawing;
|
34
|
-
|
35
|
-
using System.Text;
|
36
|
-
|
37
|
-
using System.Windows.Forms;
|
38
|
-
|
39
|
-
using System.Configuration;
|
40
|
-
|
41
|
-
using System.Data.OleDb;
|
42
|
-
|
43
|
-
using DailyReport.DB;
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
namespace DailyReport
|
48
|
-
|
49
|
-
{
|
50
|
-
|
51
|
-
public partial class UserListForm : BaseForm
|
52
|
-
|
53
|
-
{
|
54
|
-
|
55
|
-
private Rectangle dragBoxFromMouseDown;
|
56
|
-
|
57
|
-
private int rowIndexFromMouseDown;
|
58
|
-
|
59
|
-
private int rowIndexOfItemUnderMouseToDrop;
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
private void dataGridView1_MouseMove(object sender, MouseEventArgs e)
|
64
|
-
|
65
|
-
{
|
66
|
-
|
67
|
-
if ((e.Button & MouseButtons.Left) == MouseButtons.Left)
|
68
|
-
|
69
|
-
{
|
70
|
-
|
71
|
-
// If the mouse moves outside the rectangle, start the drag.
|
72
|
-
|
73
|
-
if (dragBoxFromMouseDown != Rectangle.Empty &&
|
74
|
-
|
75
|
-
!dragBoxFromMouseDown.Contains(e.X, e.Y))
|
76
|
-
|
77
|
-
{
|
78
|
-
|
79
|
-
// Proceed with the drag and drop, passing in the list item.
|
80
|
-
|
81
|
-
DragDropEffects dropEffect = dataGridView1.DoDragDrop(
|
82
|
-
|
83
|
-
dataGridView1.Rows[rowIndexFromMouseDown],
|
84
|
-
|
85
|
-
DragDropEffects.Move);
|
86
|
-
|
87
|
-
}
|
88
|
-
|
89
|
-
}
|
90
|
-
|
91
|
-
}
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
private void dataGridView1_MouseDown(object sender, MouseEventArgs e)
|
96
|
-
|
97
|
-
{
|
98
|
-
|
99
|
-
// Get the index of the item the mouse is below.
|
100
|
-
|
101
|
-
rowIndexFromMouseDown = dataGridView1.HitTest(e.X, e.Y).RowIndex;
|
102
|
-
|
103
|
-
if (rowIndexFromMouseDown != -1)
|
104
|
-
|
105
|
-
{
|
106
|
-
|
107
|
-
// Remember the point where the mouse down occurred.
|
108
|
-
|
109
|
-
// The DragSize indicates the size that the mouse can move
|
110
|
-
|
111
|
-
// before a drag event should be started.
|
112
|
-
|
113
|
-
Size dragSize = SystemInformation.DragSize;
|
114
|
-
|
115
|
-
// Create a rectangle using the DragSize, with the mouse position being
|
116
|
-
|
117
|
-
// at the center of the rectangle.
|
118
|
-
|
119
|
-
dragBoxFromMouseDown = new Rectangle(new Point(e.X - (dragSize.Width / 2),
|
120
|
-
|
121
|
-
e.Y - (dragSize.Height / 2)),
|
122
|
-
|
123
|
-
dragSize);
|
124
|
-
|
125
|
-
}
|
126
|
-
|
127
|
-
else
|
128
|
-
|
129
|
-
// Reset the rectangle if the mouse is not over an item in the ListBox.
|
130
|
-
|
131
|
-
dragBoxFromMouseDown = Rectangle.Empty;
|
132
|
-
|
133
|
-
}
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
private void dataGridView1_DragOver(object sender, DragEventArgs e)
|
138
|
-
|
139
|
-
{
|
140
|
-
|
141
|
-
e.Effect = DragDropEffects.Move;
|
142
|
-
|
143
|
-
}
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
private void dataGridView1_DragDrop(object sender, DragEventArgs e)
|
148
|
-
|
149
|
-
{
|
150
|
-
|
151
|
-
// The mouse locations are relative to the screen, so they must be
|
152
|
-
|
153
|
-
// converted to client coordinates.
|
154
|
-
|
155
|
-
Point clientPoint = dataGridView1.PointToClient(new Point(e.X, e.Y));
|
156
|
-
|
157
|
-
// Get the row index of the item the mouse is below.
|
158
|
-
|
159
|
-
rowIndexOfItemUnderMouseToDrop =
|
160
|
-
|
161
|
-
dataGridView1.HitTest(clientPoint.X, clientPoint.Y).RowIndex;
|
162
|
-
|
163
|
-
// If the drag operation was a move then remove and insert the row.
|
164
|
-
|
165
|
-
if (e.Effect == DragDropEffects.Move)
|
166
|
-
|
167
|
-
{
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
DataTable dt = (DataTable)dataGridView1.DataSource;
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
object[] rowArray = dt.Rows[rowIndexFromMouseDown].ItemArray;
|
176
|
-
|
177
|
-
DataRow row = dt.NewRow();
|
178
|
-
|
179
|
-
row.ItemArray = rowArray;
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
dt.Rows.RemoveAt(rowIndexFromMouseDown);
|
184
|
-
|
185
|
-
dt.Rows.InsertAt(row, rowIndexOfItemUnderMouseToDrop);
|
186
|
-
|
187
|
-
}
|
188
|
-
|
189
|
-
}
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
<他、ロードイベント等 省略>
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
}
|
198
|
-
|
199
|
-
}
|
200
|
-
|
201
|
-
```
|
202
|
-
|
203
|
-
|
204
|
-
|
205
21
|
###試したこと
|
206
22
|
|
207
23
|
DataGridViewのプロパティの問題かと思いましたが、該当するものを見つけられませんでした。
|
2
リンク編集
test
CHANGED
File without changes
|
test
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
下記を参考に、ほぼ同じコードにしているのですが、うまくいかず困っています。
|
6
6
|
|
7
|
-
https://social.msdn.microsoft.com/Forums/ja-JP/e59a4043-6298-4653-809f-5c8fcf04f2e6/datagridview?forum=csharpgeneralja
|
7
|
+
[リンク内容](https://social.msdn.microsoft.com/Forums/ja-JP/e59a4043-6298-4653-809f-5c8fcf04f2e6/datagridview?forum=csharpgeneralja)
|
8
8
|
|
9
9
|
|
10
10
|
|
1
初心者アイコンの追加
test
CHANGED
File without changes
|
test
CHANGED
File without changes
|