質問編集履歴
3
## 追記の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -34,18 +34,14 @@
|
|
34
34
|
|
35
35
|
以下を参考に書いてみました。
|
36
36
|
|
37
|
+
期待通りの動作になりました。
|
38
|
+
|
37
39
|
|
38
40
|
|
39
41
|
https://stackoverflow.com/questions/2825771/how-can-we-do-pagination-in-datagridview-in-winform
|
40
42
|
|
41
43
|
|
42
44
|
|
43
|
-
総ページ数を表示すべきところが、1ページの項目数になってしまいます。
|
44
|
-
|
45
|
-
あと少しだと思うんですが...
|
46
|
-
|
47
|
-
|
48
|
-
|
49
45
|
![イメージ説明](582938f64eb13c2987671cf8e4f67d06.png)
|
50
46
|
|
51
47
|
![イメージ説明](072ca0191b0c264c92ea3eacfacdd4fe.png)
|
2
コード修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -48,8 +48,6 @@
|
|
48
48
|
|
49
49
|
![イメージ説明](582938f64eb13c2987671cf8e4f67d06.png)
|
50
50
|
|
51
|
-
|
52
|
-
|
53
51
|
![イメージ説明](072ca0191b0c264c92ea3eacfacdd4fe.png)
|
54
52
|
|
55
53
|
|
@@ -236,8 +234,6 @@
|
|
236
234
|
|
237
235
|
this.dataGridView1.DataSource = tables[bindingSource.Position];
|
238
236
|
|
239
|
-
this.bindingSource.DataSource = tables[bindingSource.Position];
|
240
|
-
|
241
237
|
}
|
242
238
|
|
243
239
|
}
|
1
情報の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -25,3 +25,225 @@
|
|
25
25
|
|
26
26
|
|
27
27
|
https://dobon.net/vb/bbs/log3-29/17906.html
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
## 追記
|
34
|
+
|
35
|
+
以下を参考に書いてみました。
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
https://stackoverflow.com/questions/2825771/how-can-we-do-pagination-in-datagridview-in-winform
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
総ページ数を表示すべきところが、1ページの項目数になってしまいます。
|
44
|
+
|
45
|
+
あと少しだと思うんですが...
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
![イメージ説明](582938f64eb13c2987671cf8e4f67d06.png)
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
![イメージ説明](072ca0191b0c264c92ea3eacfacdd4fe.png)
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
```C#
|
58
|
+
|
59
|
+
//
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
using System;
|
64
|
+
|
65
|
+
using System.Collections.Generic;
|
66
|
+
|
67
|
+
using System.ComponentModel;
|
68
|
+
|
69
|
+
using System.Data;
|
70
|
+
|
71
|
+
using System.Drawing;
|
72
|
+
|
73
|
+
using System.Linq;
|
74
|
+
|
75
|
+
using System.Text;
|
76
|
+
|
77
|
+
using System.Threading.Tasks;
|
78
|
+
|
79
|
+
using System.Windows.Forms;
|
80
|
+
|
81
|
+
using System.IO;
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
namespace DataGridPaging
|
86
|
+
|
87
|
+
{
|
88
|
+
|
89
|
+
public partial class Form1 : Form
|
90
|
+
|
91
|
+
{
|
92
|
+
|
93
|
+
public DataTable dataTable = new DataTable();
|
94
|
+
|
95
|
+
public BindingSource bindingSource = new BindingSource();
|
96
|
+
|
97
|
+
public BindingList<DataTable> tables = new BindingList<DataTable>();
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
// 1ページで表示する行数
|
102
|
+
|
103
|
+
public int pageSize = 1000;
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
public Form1()
|
108
|
+
|
109
|
+
{
|
110
|
+
|
111
|
+
InitializeComponent();
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
// データサンプル(10000行)
|
116
|
+
|
117
|
+
// 以下の型式で10000行
|
118
|
+
|
119
|
+
// 1,行1,hoge1,fuga2,aaaaaaaaaaaaaaaaaaaa1
|
120
|
+
|
121
|
+
ReadData();
|
122
|
+
|
123
|
+
}
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
public void ReadData()
|
128
|
+
|
129
|
+
{
|
130
|
+
|
131
|
+
this.dataTable.Columns.Add("列1", typeof(string));
|
132
|
+
|
133
|
+
this.dataTable.Columns.Add("列2", typeof(string));
|
134
|
+
|
135
|
+
this.dataTable.Columns.Add("列3", typeof(string));
|
136
|
+
|
137
|
+
this.dataTable.Columns.Add("列4", typeof(string));
|
138
|
+
|
139
|
+
this.dataTable.Columns.Add("列5", typeof(string));
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
using(StreamReader sr = new StreamReader(@"data.csv", System.Text.Encoding.GetEncoding("shift_jis")))
|
144
|
+
|
145
|
+
{
|
146
|
+
|
147
|
+
while(!sr.EndOfStream)
|
148
|
+
|
149
|
+
{
|
150
|
+
|
151
|
+
var line = sr.ReadLine();
|
152
|
+
|
153
|
+
var datas = line.Split(',');
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
dataTable.Rows.Add(datas[0], datas[1], datas[2], datas[3], datas[4]);
|
158
|
+
|
159
|
+
}
|
160
|
+
|
161
|
+
}
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
}
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
private void button1_Click(object sender, EventArgs e)
|
170
|
+
|
171
|
+
{
|
172
|
+
|
173
|
+
SetPagedDataSource();
|
174
|
+
|
175
|
+
}
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
private void SetPagedDataSource()
|
180
|
+
|
181
|
+
{
|
182
|
+
|
183
|
+
DataTable dt = null;
|
184
|
+
|
185
|
+
int counter = 1;
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
foreach (DataRow dr in this.dataTable.Rows)
|
190
|
+
|
191
|
+
{
|
192
|
+
|
193
|
+
if (counter == 1)
|
194
|
+
|
195
|
+
{
|
196
|
+
|
197
|
+
dt = dataTable.Clone();
|
198
|
+
|
199
|
+
tables.Add(dt);
|
200
|
+
|
201
|
+
}
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
dt.Rows.Add(dr.ItemArray);
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
if (pageSize < ++counter)
|
210
|
+
|
211
|
+
{
|
212
|
+
|
213
|
+
counter = 1;
|
214
|
+
|
215
|
+
}
|
216
|
+
|
217
|
+
}
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
this.bindingNavigator1.BindingSource = bindingSource;
|
222
|
+
|
223
|
+
bindingSource.DataSource = tables;
|
224
|
+
|
225
|
+
bindingSource.PositionChanged += bindingSource_PositionChanged;
|
226
|
+
|
227
|
+
bindingSource_PositionChanged(bindingSource, EventArgs.Empty);
|
228
|
+
|
229
|
+
}
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
private void bindingSource_PositionChanged(object sender, EventArgs e)
|
234
|
+
|
235
|
+
{
|
236
|
+
|
237
|
+
this.dataGridView1.DataSource = tables[bindingSource.Position];
|
238
|
+
|
239
|
+
this.bindingSource.DataSource = tables[bindingSource.Position];
|
240
|
+
|
241
|
+
}
|
242
|
+
|
243
|
+
}
|
244
|
+
|
245
|
+
}
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
```
|