-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCellCollection.cs
More file actions
80 lines (68 loc) · 2.3 KB
/
CellCollection.cs
File metadata and controls
80 lines (68 loc) · 2.3 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Linq;
namespace EngineersTools
{
public class CellCollection : ReadOnlyObservableCollection<Cell>
{
private static ObservableCollection<Cell> _Cells = new ObservableCollection<Cell>();
public CellCollection() : base(_Cells)
{
CollectionChanged += _CollectionChanged;
}
private void _CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
switch (e.Action)
{
case NotifyCollectionChangedAction.Add:
ItemsAdded?.Invoke(this, e);
break;
case NotifyCollectionChangedAction.Remove:
ItemsRemoved?.Invoke(this, e);
break;
case NotifyCollectionChangedAction.Replace:
break;
case NotifyCollectionChangedAction.Move:
break;
case NotifyCollectionChangedAction.Reset:
break;
default:
break;
}
}
public delegate void ItemsAddedHandler(object sender, NotifyCollectionChangedEventArgs e);
public event ItemsAddedHandler ItemsAdded;
public delegate void ItemsRemovedHandler(object sender, NotifyCollectionChangedEventArgs e);
public event ItemsRemovedHandler ItemsRemoved;
public object this[int row, int column]
{
get
{
return _GetCell(row, column)?.Value;
}
set
{
var cell = _GetCell(row, column);
if (cell == null)
{
cell = new Cell() { Row = row, Column = column, Value = value };
_Cells.Add(cell);
}
else
{
_Cells[_Cells.IndexOf(cell)].Value = value;
}
}
}
public void DeleteRow(int rowNumber)
{
}
public void DeleteColumn(int columnNumber)
{
}
private Cell _GetCell(int row, int column)
{
return _Cells.Where(c => c.Row == row && c.Column == column).FirstOrDefault();
}
}
}