-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVirtualHandler2.cs
More file actions
57 lines (48 loc) · 1.63 KB
/
Copy pathVirtualHandler2.cs
File metadata and controls
57 lines (48 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Version 2
using System;
using System.ComponentModel;
using System.Windows.Forms;
namespace Antropod.DataGridViewVirtual
{
public class TwoDimensionalArrayView
{
private DataGridView dataGridView;
public double[,] data;
public TwoDimensionalArrayView(DataGridView dataGridView,
double[,] data = null)
{
this.dataGridView = dataGridView;
SetDataGridParameters();
Data = data;
}
public double[,] Data
{
set
{
this.data = value;
dataGridView.ColumnCount = data != null ? data.GetLength(1) : 0;
dataGridView.RowCount = data != null ? data.GetLength(0) : 0;
dataGridView.Invalidate();
}
}
private void SetDataGridParameters()
{
dataGridView.ReadOnly = true;
dataGridView.VirtualMode = true;
dataGridView.AllowUserToAddRows = false;
dataGridView.AllowUserToResizeRows = false;
dataGridView.Columns.Clear();
dataGridView.CellValueNeeded += new
DataGridViewCellValueEventHandler(CellValueNeeded);
}
private void CellValueNeeded(object sender, DataGridViewCellValueEventArgs args)
{
args.Value = 0;
if (data == null) return;
if (args.ColumnIndex >= data.GetLength(1)) return;
if (args.RowIndex >= data.GetLength(0)) return;
if (dataGridView.Rows[args.RowIndex].IsNewRow) return;
args.Value = data[args.RowIndex, args.ColumnIndex];
}
}
}