-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrmMain.cs
155 lines (121 loc) · 4.51 KB
/
frmMain.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
namespace ComboBugRepro
{
using System;
using System.Windows.Forms;
public partial class frmMain : Form
{
private static readonly string[] AppOptions = new[] { "App_1", "App_2", "App_3" };
private static readonly string[] OwnerOptions = new[] { "Control", "RaceEng", "Engine", "Rack" };
public enum FileOwner
{
ControlEngineer,
RaceEngineer,
EngineEngineer,
RackMan,
}
int RowCount;
public frmMain()
{
InitializeComponent();
}
private void frmDirSetup_Load(object sender, EventArgs e)
{
// Configure the display
ClearDirTable();
}
private void cmdUpdate_Click(object sender, EventArgs e)
{
// Configure the display
ClearDirTable();
PopulateDirTable();
}
public void PopulateDirTable()
{
tableDirs.SuspendLayout();
AddNewRow("App_1", "Foo", FileOwner.EngineEngineer);
AddNewRow("App_2", "Bar", FileOwner.ControlEngineer);
AddNewRow("App_3", "Quux", FileOwner.RaceEngineer);
tableDirs.Visible = true;
tableDirs.ResumeLayout();
this.Height = (tableDirs.RowCount * 33) + 180;
}
public void ClearDirTable()
{
int Index = RowCount - 1;
tableDirs.Visible = false;
// Remove controls for each row
while (Index >= 0)
{
for (int i = 0; i < tableDirs.ColumnCount; i++)
{
var control = tableDirs.GetControlFromPosition(0, Index);
tableDirs.Controls.Remove(control);
}
RowCount--;
tableDirs.RowCount = RowCount;
Index--;
}
this.Height = (tableDirs.RowCount * 33) + 180;
}
private void AddNewRow(
string application,
string area,
FileOwner owner)
{
RowCount++;
//Add the controls that constitute a row
var cboApp = new ComboBox
{
Anchor = AnchorStyles.Right | AnchorStyles.Left,
DropDownStyle = ComboBoxStyle.DropDownList
};
cboApp.Items.AddRange(AppOptions);
cboApp.SelectedIndexChanged += new EventHandler(cboApp_SelectedIndexChanged);
tableDirs.Controls.Add(cboApp);
var txtArea = new TextBox
{
Anchor = AnchorStyles.Right | AnchorStyles.Left
};
tableDirs.Controls.Add(txtArea);
var cboOwner = new ComboBox
{
Anchor = AnchorStyles.Right | AnchorStyles.Left,
DropDownStyle = ComboBoxStyle.DropDownList
};
cboOwner.Items.AddRange(OwnerOptions);
tableDirs.Controls.Add(cboOwner);
var cboTrackParam = new ComboBox
{
Anchor = AnchorStyles.Right | AnchorStyles.Left,
DropDownStyle = ComboBoxStyle.DropDownList
};
tableDirs.Controls.Add(cboTrackParam);
tableDirs.RowCount = RowCount;
// Populate the controls with the input arguments
if (!cboApp.Items.Contains(application))
{
return;
}
cboApp.SelectedItem = application;
// We've already hit the bug by now, these lines are superfluous
txtArea.Text = area;
cboOwner.SelectedItem = OwnerOptions[(int)owner];
this.Height = (tableDirs.RowCount * 33) + 180;
tableDirs.Visible = true;
}
void cboApp_SelectedIndexChanged(object sender, EventArgs e)
{
var cboApp = (ComboBox)sender;
// Update the available "Tracking parameters"
var cboAppPosition = tableDirs.GetPositionFromControl(cboApp);
var cboTrackParam = (ComboBox)tableDirs.GetControlFromPosition(3, cboAppPosition.Row);
cboTrackParam.Items.Clear();
// N.B. In the real application, the avaiable list depends on the cboApp
// selected item (hence the event handler).
// This is enough to repro the bug, though.
cboTrackParam.Items.Add("No Tracking");
#warning This line triggers the bug (when hit whilst populating the table)
cboTrackParam.SelectedIndex = 0;
}
}
}