diff options
| author | mo.khan <mo.khan@a0a4a051-f042-0410-9e78-9fae330bdb64> | 2008-01-05 07:16:52 +0000 |
|---|---|---|
| committer | mo.khan <mo.khan@a0a4a051-f042-0410-9e78-9fae330bdb64> | 2008-01-05 07:16:52 +0000 |
| commit | 8c137f229c36a777ead5cacb3350cb8692646292 (patch) | |
| tree | 92876c5da0ffd17767e38f94a44415ac27a3c73e /DesignPatterns/src/app/DesignPatterns.Adapter/DesktopDropDownList.cs | |
| parent | cbdf42a6427eef7849d1ab7731f9185b410431d3 (diff) | |
git-svn-id: http://mokhan.googlecode.com/svn/trunk@9 a0a4a051-f042-0410-9e78-9fae330bdb64
Diffstat (limited to 'DesignPatterns/src/app/DesignPatterns.Adapter/DesktopDropDownList.cs')
| -rw-r--r-- | DesignPatterns/src/app/DesignPatterns.Adapter/DesktopDropDownList.cs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/DesignPatterns/src/app/DesignPatterns.Adapter/DesktopDropDownList.cs b/DesignPatterns/src/app/DesignPatterns.Adapter/DesktopDropDownList.cs new file mode 100644 index 0000000..cc876c4 --- /dev/null +++ b/DesignPatterns/src/app/DesignPatterns.Adapter/DesktopDropDownList.cs @@ -0,0 +1,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;
+ }
+}
\ No newline at end of file |
