-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathSelectedSeriesListBox.cs
108 lines (88 loc) · 2.96 KB
/
SelectedSeriesListBox.cs
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace HdbPoet
{
public partial class SelectedSeriesListBox : UserControl
{
public SelectedSeriesListBox()
{
InitializeComponent();
}
GraphData ds;
public void SetDataSource(GraphData value)
{
ds = value;
FillListBox();
}
private void FillListBox()
{
this.listBox.Items.Clear();
foreach (var item in ds.SeriesRows)
{
listBox.Items.Add(item.DisplayName);
}
}
public void RemoveSelected()
{
var rows = new List<TimeSeriesDataSet.SeriesRow>();
TimeSeriesDataSet.SeriesRow[] x = ds.SeriesRows.ToArray();
for (int i = 0; i < listBox.SelectedIndices.Count; i++)
{
rows.Add(x[listBox.SelectedIndices[i]]);
}
for (int i = 0; i < rows.Count; i++)
{
var r = rows[i];
r.Delete();
r.Table.AcceptChanges();
//r.AcceptChanges();
//rows[i].Table.AcceptChanges();
//ds.SeriesRows.RemoveSeriesRow(rows[i]);
}
FillListBox();
}
/// <summary>
/// We are relying on order in DataTable.
/// find index(SeriesNumber) for selected and above
/// so they can be swaped.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonMoveGraphUp_Click(object sender, EventArgs e)
{
int idx = this.listBox.SelectedIndex;
if (idx < 0 || idx == 0) // cant move up if you are at the top.
return;
MoveSeries(idx, idx-1);
}
private void buttonMoveGraphDown_Click(object sender, EventArgs e)
{
int idx = this.listBox.SelectedIndex;
if (idx < 0 || idx == (this.listBox.Items.Count - 1))
return;
MoveSeries(idx, idx + 1);
}
private void MoveSeries(int idx, int idxNew )
{
var Series = ds.SeriesRows.ToArray();
var selected = Series[idx];
var destination = Series[idxNew];
TimeSeriesDataSet.SeriesDataTable table = (TimeSeriesDataSet.SeriesDataTable)selected.Table;
int insertIndex = table.FindRowIndex(destination.SeriesNumber);
object[] array = selected.ItemArray;
var newRow = table.NewRow();
newRow.ItemArray = array;
selected.Delete();
table.Rows.InsertAt(newRow, insertIndex);
table.AcceptChanges();
FillListBox();
listBox.SelectedIndex = idxNew;
}
}
}