2008-03-27 Carlos Alberto Cortez <calberto.cortez@gmail.com>
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / DataGridViewComboBoxColumn.cs
1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
8 // 
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
11 // 
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 //
20 // Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
21 //
22 // Author:
23 //      Pedro Martínez Juliá <pedromj@gmail.com>
24 //
25
26
27 #if NET_2_0
28
29 using System.ComponentModel;
30 using System.Drawing.Design;
31 using System.Drawing;
32
33 namespace System.Windows.Forms {
34
35         [ToolboxBitmap ("")]
36         [Designer ("System.Windows.Forms.Design.DataGridViewComboBoxColumnDesigner, " + Consts.AssemblySystem_Design,
37                    "System.ComponentModel.Design.IDesigner")]
38         public class DataGridViewComboBoxColumn : DataGridViewColumn
39         {
40                 private bool autoComplete;
41                 private DataGridViewComboBoxDisplayStyle displayStyle;
42                 private bool displayStyleForCurrentCellOnly;
43                 private FlatStyle flatStyle;
44
45                 public DataGridViewComboBoxColumn ()
46                 {
47                         CellTemplate = new DataGridViewComboBoxCell();
48                         SortMode = DataGridViewColumnSortMode.NotSortable;
49                         autoComplete = true;
50                         displayStyle = DataGridViewComboBoxDisplayStyle.DropDownButton;
51                         displayStyleForCurrentCellOnly = false;
52                 }
53
54                 [Browsable (true)]
55                 [DefaultValue (true)]
56                 public bool AutoComplete {
57                         get { return autoComplete; }
58                         set { autoComplete = value; }
59                 }
60
61                 [Browsable (false)]
62                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
63                 public override DataGridViewCell CellTemplate {
64                         get { return base.CellTemplate; }
65                         set { base.CellTemplate = value as DataGridViewComboBoxCell; }
66                 }
67
68                 [AttributeProvider (typeof (IListSource))]
69                 [DefaultValue (null)]
70                 [RefreshProperties (RefreshProperties.Repaint)]
71                 public object DataSource {
72                         get {
73                                 if (base.CellTemplate == null) {
74                                         throw new InvalidOperationException("CellTemplate is null.");
75                                 }
76                                 return (base.CellTemplate as DataGridViewComboBoxCell).DataSource; }
77                         set {
78                                 if (base.CellTemplate == null) {
79                                         throw new InvalidOperationException("CellTemplate is null.");
80                                 }
81                                 (base.CellTemplate as DataGridViewComboBoxCell).DataSource = value;
82                         }
83                 }
84
85                 [Editor ("System.Windows.Forms.Design.DataMemberFieldEditor, " + Consts.AssemblySystem_Design,
86                          "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
87                 [DefaultValue ("")]
88                 [TypeConverter ("System.Windows.Forms.Design.DataMemberFieldConverter, " + Consts.AssemblySystem_Design)]
89                 public string DisplayMember {
90                         get {
91                                 if (base.CellTemplate == null) {
92                                         throw new InvalidOperationException("CellTemplate is null.");
93                                 }
94                                 return (base.CellTemplate as DataGridViewComboBoxCell).DisplayMember;
95                         }
96                         set {
97                                 if (base.CellTemplate == null) {
98                                         throw new InvalidOperationException("CellTemplate is null.");
99                                 }
100                                 (base.CellTemplate as DataGridViewComboBoxCell).DisplayMember = value;
101                         }
102                 }
103
104                 [DefaultValue (DataGridViewComboBoxDisplayStyle.DropDownButton)]
105                 public DataGridViewComboBoxDisplayStyle DisplayStyle {
106                         get { return displayStyle; }
107                         set { displayStyle = value; }
108                 }
109
110                 [DefaultValue (false)]
111                 public bool DisplayStyleForCurrentCellOnly {
112                         get { return displayStyleForCurrentCellOnly; }
113                         set { displayStyleForCurrentCellOnly = value; }
114                 }
115
116                 [DefaultValue (1)]
117                 public int DropDownWidth {
118                         get {
119                                 if (base.CellTemplate == null) {
120                                         throw new InvalidOperationException("CellTemplate is null.");
121                                 }
122                                 return (base.CellTemplate as DataGridViewComboBoxCell).DropDownWidth;
123                         }
124                         set {
125                                 if (value < 1) {
126                                         throw new ArgumentException("Value is less than 1.");
127                                 }
128                                 if (base.CellTemplate == null) {
129                                         throw new InvalidOperationException("CellTemplate is null.");
130                                 }
131                                 (base.CellTemplate as DataGridViewComboBoxCell).DropDownWidth = value;
132                         }
133                 }
134
135                 [DefaultValue (FlatStyle.Standard)]
136                 public FlatStyle FlatStyle {
137                         get { return flatStyle; }
138                         set { flatStyle = value; }
139                 }
140
141                 [Editor ("System.Windows.Forms.Design.StringCollectionEditor, " + Consts.AssemblySystem_Design,
142                          "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
143                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
144                 public DataGridViewComboBoxCell.ObjectCollection Items {
145                         get {
146                                 if (base.CellTemplate == null) {
147                                         throw new InvalidOperationException("CellTemplate is null.");
148                                 }
149                                 return (base.CellTemplate as DataGridViewComboBoxCell).Items;
150                         }
151                 }
152
153                 [DefaultValue (8)]
154                 public int MaxDropDownItems {
155                         get {
156                                 if (base.CellTemplate == null) {
157                                         throw new InvalidOperationException("CellTemplate is null.");
158                                 }
159                                 return (base.CellTemplate as DataGridViewComboBoxCell).MaxDropDownItems;
160                         }
161                         set {
162                                 if (base.CellTemplate == null) {
163                                         throw new InvalidOperationException("CellTemplate is null.");
164                                 }
165                                 (base.CellTemplate as DataGridViewComboBoxCell).MaxDropDownItems = value;
166                         }
167                 }
168
169                 [DefaultValue (false)]
170                 public bool Sorted {
171                         get {
172                                 if (base.CellTemplate == null) {
173                                         throw new InvalidOperationException("CellTemplate is null.");
174                                 }
175                                 return (base.CellTemplate as DataGridViewComboBoxCell).Sorted;
176                         }
177                         set {
178                                 if (base.CellTemplate == null) {
179                                         throw new InvalidOperationException("CellTemplate is null.");
180                                 }
181                                 (base.CellTemplate as DataGridViewComboBoxCell).Sorted = value;
182                         }
183                 }
184
185                 [DefaultValue ("")]
186                 [Editor ("System.Windows.Forms.Design.DataMemberFieldEditor, " + Consts.AssemblySystem_Design,
187                          "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
188                 [TypeConverter ("System.Windows.Forms.Design.DataMemberFieldConverter, " + Consts.AssemblySystem_Design)]
189                 public string ValueMember {
190                         get {
191                                 if (base.CellTemplate == null) {
192                                         throw new InvalidOperationException("CellTemplate is null.");
193                                 }
194                                 return (base.CellTemplate as DataGridViewComboBoxCell).ValueMember;
195                         }
196                         set {
197                                 if (base.CellTemplate == null) {
198                                         throw new InvalidOperationException("CellTemplate is null.");
199                                 }
200                                 (base.CellTemplate as DataGridViewComboBoxCell).ValueMember = value;
201                         }
202                 }
203
204                 public override object Clone ()
205                 {
206                         DataGridViewComboBoxColumn col = (DataGridViewComboBoxColumn) base.Clone();
207                         col.autoComplete = this.autoComplete;
208                         col.displayStyle = this.displayStyle;
209                         col.displayStyleForCurrentCellOnly = this.displayStyleForCurrentCellOnly;
210                         col.flatStyle = this.flatStyle;
211                         col.CellTemplate = (DataGridViewComboBoxCell) this.CellTemplate.Clone();
212                         return col;
213                 }
214
215                 public override string ToString ()
216                 {
217                         return GetType().Name;
218                 }
219
220         }
221
222 }
223
224 #endif