1
1
using System ;
2
+ using System . ComponentModel ;
2
3
using System . Data ;
3
4
using System . Drawing ;
4
5
using System . Windows . Forms ;
@@ -8,10 +9,16 @@ namespace Virtual_Data_Warehouse
8
9
{
9
10
public class TemplateGridView : DataGridView
10
11
{
12
+ internal BindingList < LocalTeamConnection > bindingList ;
13
+ internal BindingSource bindingSource ;
14
+ internal TeamConfiguration TeamConfiguration ;
15
+
11
16
public TemplateGridView ( TeamConfiguration teamConfiguration )
12
17
{
13
18
#region Generic properties
14
19
20
+ TeamConfiguration = teamConfiguration ;
21
+
15
22
// Disable resizing for performance, will be enabled after binding.
16
23
RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode . DisableResizing ;
17
24
ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode . DisableResizing ;
@@ -54,17 +61,32 @@ public TemplateGridView(TeamConfiguration teamConfiguration)
54
61
} ;
55
62
Columns . Add ( TemplateType ) ;
56
63
57
- DataGridViewComboBoxColumn TemplateConnectionKey = new DataGridViewComboBoxColumn
64
+ // Connections list (combo box) column.
65
+ DataGridViewComboBoxColumn TemplateConnectionKey = new DataGridViewComboBoxColumn ( ) ;
66
+
67
+ TemplateConnectionKey . Name = TemplateGridColumns . TemplateConnectionKey . ToString ( ) ;
68
+ TemplateConnectionKey . HeaderText = "Connection" ;
69
+ TemplateConnectionKey . DataPropertyName = TemplateGridColumns . TemplateConnectionKey . ToString ( ) ;
70
+ TemplateConnectionKey . DisplayStyle = DataGridViewComboBoxDisplayStyle . Nothing ;
71
+
72
+ TemplateConnectionKey . DataSource = null ;
73
+
74
+ bindingList = new BindingList < LocalTeamConnection > ( ) ;
75
+ bindingSource = new BindingSource ( ) ;
76
+
77
+ bindingSource . DataSource = bindingList ;
78
+ TemplateConnectionKey . DataSource = bindingSource ;
79
+
80
+ var connectionList = LocalTeamConnection . GetConnections ( teamConfiguration . ConnectionDictionary ) ;
81
+
82
+ foreach ( LocalTeamConnection teamConnection in connectionList )
58
83
{
59
- Name = TemplateGridColumns . TemplateConnectionKey . ToString ( ) ,
60
- HeaderText = "Connection Key" ,
61
- DataPropertyName = TemplateGridColumns . TemplateConnectionKey . ToString ( ) ,
62
- DisplayStyle = DataGridViewComboBoxDisplayStyle . Nothing ,
63
- DataSource = LocalTeamConnection . GetConnections ( teamConfiguration . ConnectionDictionary ) ,
64
- DisplayMember = "ConnectionKey" ,
65
- ValueMember = "ConnectionId" ,
66
- ValueType = typeof ( string )
67
- } ;
84
+ bindingList . Add ( teamConnection ) ;
85
+ }
86
+
87
+ TemplateConnectionKey . DisplayMember = "ConnectionKey" ;
88
+ TemplateConnectionKey . ValueMember = "ConnectionId" ;
89
+
68
90
Columns . Add ( TemplateConnectionKey ) ;
69
91
70
92
DataGridViewTextBoxColumn TemplateOutputFileConvention = new DataGridViewTextBoxColumn
@@ -97,11 +119,23 @@ public TemplateGridView(TeamConfiguration teamConfiguration)
97
119
#region Event Handlers
98
120
99
121
CurrentCellDirtyStateChanged += dataGridViewTemplateCollection_CurrentCellDirtyStateChanged ;
100
- // DataError += dataGridViewDataError;
122
+ DataError += dataGridViewDataError ;
101
123
102
124
#endregion
103
125
}
104
126
127
+ public void RefreshComboboxItems ( )
128
+ {
129
+ bindingList . Clear ( ) ;
130
+
131
+ var connectionList = LocalTeamConnection . GetConnections ( TeamConfiguration . ConnectionDictionary ) ;
132
+
133
+ foreach ( LocalTeamConnection teamConnection in connectionList )
134
+ {
135
+ bindingList . Add ( teamConnection ) ;
136
+ }
137
+ }
138
+
105
139
private void dataGridViewDataError ( object sender , DataGridViewDataErrorEventArgs e )
106
140
{
107
141
MessageBox . Show ( "Error happened " + e . Context ) ;
0 commit comments