blob: cc876c4a7b47ce2f66635f1e157640c93061b674 (
plain)
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
|
using System.Collections.Generic;
using System.Windows.Forms;
namespace DesignPatterns.Adapter {
public class DesktopDropDownList : IDropDownListAdapter {
public DesktopDropDownList( ComboBox dropDown ) {
_dropDown = dropDown;
_pairs = new Dictionary< string, IDropDownListItem >( );
}
public void BindTo( IEnumerable< IDropDownListItem > pairs ) {
if ( pairs != null ) {
_pairs = new Dictionary< string, IDropDownListItem >( );
foreach ( IDropDownListItem pair in pairs ) {
_dropDown.Items.Add( pair.Text );
_pairs.Add( pair.Text, pair );
}
_dropDown.SelectedIndex = 0;
}
}
public IDropDownListItem SelectedItem {
get { return !string.IsNullOrEmpty( _dropDown.Text ) ? _pairs[ _dropDown.Text ] : null; }
}
private ComboBox _dropDown;
private IDictionary< string, IDropDownListItem > _pairs;
}
}
|