質問編集履歴
3
## 追記の修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -16,12 +16,10 @@
|
|
16
16
|
|
17
17
|
## 追記
|
18
18
|
以下を参考に書いてみました。
|
19
|
+
期待通りの動作になりました。
|
19
20
|
|
20
21
|
https://stackoverflow.com/questions/2825771/how-can-we-do-pagination-in-datagridview-in-winform
|
21
22
|
|
22
|
-
総ページ数を表示すべきところが、1ページの項目数になってしまいます。
|
23
|
-
あと少しだと思うんですが...
|
24
|
-
|
25
23
|

|
26
24
|

|
27
25
|
|
2
コード修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -23,7 +23,6 @@
|
|
23
23
|
あと少しだと思うんですが...
|
24
24
|
|
25
25
|

|
26
|
-
|
27
26
|

|
28
27
|
|
29
28
|
```C#
|
@@ -117,7 +116,6 @@
|
|
117
116
|
private void bindingSource_PositionChanged(object sender, EventArgs e)
|
118
117
|
{
|
119
118
|
this.dataGridView1.DataSource = tables[bindingSource.Position];
|
120
|
-
this.bindingSource.DataSource = tables[bindingSource.Position];
|
121
119
|
}
|
122
120
|
}
|
123
121
|
}
|
1
情報の追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -11,4 +11,115 @@
|
|
11
11
|
|
12
12
|
それらしきページのリンクがあったのですが、リンク切れでした。
|
13
13
|
|
14
|
-
https://dobon.net/vb/bbs/log3-29/17906.html
|
14
|
+
https://dobon.net/vb/bbs/log3-29/17906.html
|
15
|
+
|
16
|
+
|
17
|
+
## 追記
|
18
|
+
以下を参考に書いてみました。
|
19
|
+
|
20
|
+
https://stackoverflow.com/questions/2825771/how-can-we-do-pagination-in-datagridview-in-winform
|
21
|
+
|
22
|
+
総ページ数を表示すべきところが、1ページの項目数になってしまいます。
|
23
|
+
あと少しだと思うんですが...
|
24
|
+
|
25
|
+

|
26
|
+
|
27
|
+

|
28
|
+
|
29
|
+
```C#
|
30
|
+
//
|
31
|
+
|
32
|
+
using System;
|
33
|
+
using System.Collections.Generic;
|
34
|
+
using System.ComponentModel;
|
35
|
+
using System.Data;
|
36
|
+
using System.Drawing;
|
37
|
+
using System.Linq;
|
38
|
+
using System.Text;
|
39
|
+
using System.Threading.Tasks;
|
40
|
+
using System.Windows.Forms;
|
41
|
+
using System.IO;
|
42
|
+
|
43
|
+
namespace DataGridPaging
|
44
|
+
{
|
45
|
+
public partial class Form1 : Form
|
46
|
+
{
|
47
|
+
public DataTable dataTable = new DataTable();
|
48
|
+
public BindingSource bindingSource = new BindingSource();
|
49
|
+
public BindingList<DataTable> tables = new BindingList<DataTable>();
|
50
|
+
|
51
|
+
// 1ページで表示する行数
|
52
|
+
public int pageSize = 1000;
|
53
|
+
|
54
|
+
public Form1()
|
55
|
+
{
|
56
|
+
InitializeComponent();
|
57
|
+
|
58
|
+
// データサンプル(10000行)
|
59
|
+
// 以下の型式で10000行
|
60
|
+
// 1,行1,hoge1,fuga2,aaaaaaaaaaaaaaaaaaaa1
|
61
|
+
ReadData();
|
62
|
+
}
|
63
|
+
|
64
|
+
public void ReadData()
|
65
|
+
{
|
66
|
+
this.dataTable.Columns.Add("列1", typeof(string));
|
67
|
+
this.dataTable.Columns.Add("列2", typeof(string));
|
68
|
+
this.dataTable.Columns.Add("列3", typeof(string));
|
69
|
+
this.dataTable.Columns.Add("列4", typeof(string));
|
70
|
+
this.dataTable.Columns.Add("列5", typeof(string));
|
71
|
+
|
72
|
+
using(StreamReader sr = new StreamReader(@"data.csv", System.Text.Encoding.GetEncoding("shift_jis")))
|
73
|
+
{
|
74
|
+
while(!sr.EndOfStream)
|
75
|
+
{
|
76
|
+
var line = sr.ReadLine();
|
77
|
+
var datas = line.Split(',');
|
78
|
+
|
79
|
+
dataTable.Rows.Add(datas[0], datas[1], datas[2], datas[3], datas[4]);
|
80
|
+
}
|
81
|
+
}
|
82
|
+
|
83
|
+
}
|
84
|
+
|
85
|
+
private void button1_Click(object sender, EventArgs e)
|
86
|
+
{
|
87
|
+
SetPagedDataSource();
|
88
|
+
}
|
89
|
+
|
90
|
+
private void SetPagedDataSource()
|
91
|
+
{
|
92
|
+
DataTable dt = null;
|
93
|
+
int counter = 1;
|
94
|
+
|
95
|
+
foreach (DataRow dr in this.dataTable.Rows)
|
96
|
+
{
|
97
|
+
if (counter == 1)
|
98
|
+
{
|
99
|
+
dt = dataTable.Clone();
|
100
|
+
tables.Add(dt);
|
101
|
+
}
|
102
|
+
|
103
|
+
dt.Rows.Add(dr.ItemArray);
|
104
|
+
|
105
|
+
if (pageSize < ++counter)
|
106
|
+
{
|
107
|
+
counter = 1;
|
108
|
+
}
|
109
|
+
}
|
110
|
+
|
111
|
+
this.bindingNavigator1.BindingSource = bindingSource;
|
112
|
+
bindingSource.DataSource = tables;
|
113
|
+
bindingSource.PositionChanged += bindingSource_PositionChanged;
|
114
|
+
bindingSource_PositionChanged(bindingSource, EventArgs.Empty);
|
115
|
+
}
|
116
|
+
|
117
|
+
private void bindingSource_PositionChanged(object sender, EventArgs e)
|
118
|
+
{
|
119
|
+
this.dataGridView1.DataSource = tables[bindingSource.Position];
|
120
|
+
this.bindingSource.DataSource = tables[bindingSource.Position];
|
121
|
+
}
|
122
|
+
}
|
123
|
+
}
|
124
|
+
|
125
|
+
```
|