DataGridViewの一覧作成方法の性能検証
確認パターン
- DataGridViewに直接値設定
- DataGridViewに直接値設定(一覧明細を1000件毎に追加)
- DataGridViewに直接値設定(一覧明細を一括追加)
- DataSouceを設定(データバインド)
確認条件
- データ取得時間は含まない
- カラムは4列(文字×3、チェックボックス×1)
- 指定データを選択行にするロジックあり
- 各件数毎に5回処理しその平均値 ※200,000件のパターン1は1回のみ
- VisualStudio2015
確認結果
| 件数 |
パターン1 |
パターン2 |
パターン3 |
パターン4 |
| 1,000件 |
0.217秒 |
0.086秒 |
0.071秒 |
0.012秒 |
| 10,000件 |
8.251秒 |
0.818秒 |
0.770秒 |
0.008秒 |
| 20,000件 |
30.284秒 |
1.671秒 |
1.617秒 |
0.016秒 |
| 30,000件 |
1分06.833秒 |
2.560秒 |
0.081秒 |
0.021秒 |
| 40,000件 |
2分06.513秒 |
3.744秒 |
3.487秒 |
0.042秒 |
| 50,000件 |
3分37.362秒 |
4.432秒 |
3.529秒 |
0.036秒 |
| 200,000件 |
1時間32分55.714秒 |
27.575秒 |
29.530秒 |
0.144秒 |
確認ソース
1.DataGridViewに直接値設定
Dim oleRS As New OleDb.OleDbDataReader(ds.Tables(0)) 'DataReaderで取得時を想定
Do While oleRS.Read()
.RowCount = lRow + 1
.Item(EnumColList.Code, lRow).Value = oleRS("CD") 'コード
.Item(EnumColList.Name, lRow).Value = oleRS("NM") '名
.Item(EnumColList.Gnm, lRow).Value = oleRS("GN") '名
.Item(EnumColList.Flg, lRow).Value = oleRS("FLG") '有効区分
'カレント行を設定
If oleRS("CD").Equals(sKey) Then
.CurrentCell = .Item(EnumColList.Code, lRow)
End If
lRow += 1
Loop
oleRS.Close()
oleRS = Nothing
2.DataGridViewに直接値設定(一覧明細を1000毎に追加)
Dim oleRS As New OleDb.OleDbDataReader(ds.Tables(0)) 'DataReaderで取得時を想定
Do While oleRS.Read()
If .RowCount <= lRow Then .RowCount += 1000
.Item(EnumColList.Code, lRow).Value = oleRS("CD") 'コード
.Item(EnumColList.Name, lRow).Value = oleRS("NM") '名
.Item(EnumColList.Gnm, lRow).Value = oleRS("GN") '名
.Item(EnumColList.Flg, lRow).Value = oleRS("FLG") '有効区分
'カレント行を設定
If oleRS("CD").Equals(sKey) Then
.CurrentCell = .Item(EnumColList.Code, lRow)
End If
lRow += 1
Loop
.RowCount = lRow
oleRS.Close()
oleRS = Nothing
3.DataGridViewに直接値設定(一覧明細を一括追加)
Dim oleRS As New OleDb.OleDbDataReader(ds.Tables(0)) 'DataReaderで取得時を想定
Dim lstRow As New List(Of DataGridViewRow)
Do While oleRS.Read()
Dim row As DataGridViewRow = New DataGridViewRow()
row.CreateCells(dgvList)
With row
.Item(EnumColList.Code).Value = oleRS("CD") 'コード
.Item(EnumColList.Name).Value = oleRS("NM") '名
.Item(EnumColList.Gnm).Value = oleRS("GN") '名
.Item(EnumColList.Flg).Value = oleRS("FLG") '有効区分
End With
lstRow.Add(row)
'カレント行を設定
If oleRS("CD").Equals(sKey) Then
lRow = lstRow.Count - 1
End If
Loop
.Rows.AddRange(lstRow.ToArray)
.CurrentCell = .Item(EnumColList.Code, lRow)
oleRS.Close()
oleRS = Nothing
4.DataSouceを設定(データバインド)
If String.IsNullOrEmpty(.Columns(EnumColList.Code).DataPropertyName) Then
.Columns(EnumColList.Code).DataPropertyName = "CD"
.Columns(EnumColList.Name).DataPropertyName = "NM"
.Columns(EnumColList.Gnm).DataPropertyName = "GN"
.Columns(EnumColList.Flg).DataPropertyName = "FLG"
End If
.DataSource = ds.Tables(0)
'カレント行を設定
Dim current As DataGridViewRow = .Rows.Cast(Of DataGridViewRow)
.FirstOrDefault(Function(n) n.Cells(EnumColList.Code).Value?.Equals(sKey))
If current Is Nothing = False Then
.CurrentCell = .Item(EnumColList.Code, current.Index)
End If
最終更新:2017年04月19日 17:10