* roottypes.cs: Rename from tree.cs.
[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 namespace System.Windows.Forms {
30
31         public class DataGridViewComboBoxColumn : DataGridViewColumn {
32
33                 private bool autoComplete;
34                 private DataGridViewComboBoxDisplayStyle displayStyle;
35                 private bool displayStyleForCurrentCellsOnly;
36                 private FlatStyle flatStyle;
37
38                 public DataGridViewComboBoxColumn () {
39                         CellTemplate = new DataGridViewComboBoxCell();
40                         SortMode = DataGridViewColumnSortMode.NotSortable;
41                         autoComplete = true;
42                         displayStyle = DataGridViewComboBoxDisplayStyle.DropDownButton;
43                         displayStyleForCurrentCellsOnly = false;
44                 }
45
46                 public bool AutoComplete {
47                         get { return autoComplete; }
48                         set { autoComplete = value; }
49                 }
50
51                 public override DataGridViewCell CellTemplate {
52                         get { return base.CellTemplate; }
53                         set { base.CellTemplate = value as DataGridViewComboBoxCell; }
54                 }
55
56                 public object DataSource {
57                         get {
58                                 if (base.CellTemplate == null) {
59                                         throw new InvalidOperationException("CellTemplate is null.");
60                                 }
61                                 return (base.CellTemplate as DataGridViewComboBoxCell).DataSource; }
62                         set {
63                                 if (base.CellTemplate == null) {
64                                         throw new InvalidOperationException("CellTemplate is null.");
65                                 }
66                                 (base.CellTemplate as DataGridViewComboBoxCell).DataSource = value;
67                         }
68                 }
69
70                 public string DisplayMember {
71                         get {
72                                 if (base.CellTemplate == null) {
73                                         throw new InvalidOperationException("CellTemplate is null.");
74                                 }
75                                 return (base.CellTemplate as DataGridViewComboBoxCell).DisplayMember;
76                         }
77                         set {
78                                 if (base.CellTemplate == null) {
79                                         throw new InvalidOperationException("CellTemplate is null.");
80                                 }
81                                 (base.CellTemplate as DataGridViewComboBoxCell).DisplayMember = value;
82                         }
83                 }
84
85                 public DataGridViewComboBoxDisplayStyle DisplayStyle {
86                         get { return displayStyle; }
87                         set { displayStyle = value; }
88                 }
89
90                 public bool DisplayStyleForCurrentCellsOnly {
91                         get { return displayStyleForCurrentCellsOnly; }
92                         set { displayStyleForCurrentCellsOnly = value; }
93                 }
94
95                 public int DropDownWidth {
96                         get {
97                                 if (base.CellTemplate == null) {
98                                         throw new InvalidOperationException("CellTemplate is null.");
99                                 }
100                                 return (base.CellTemplate as DataGridViewComboBoxCell).DropDownWidth;
101                         }
102                         set {
103                                 if (value < 1) {
104                                         throw new ArgumentException("Value is less than 1.");
105                                 }
106                                 if (base.CellTemplate == null) {
107                                         throw new InvalidOperationException("CellTemplate is null.");
108                                 }
109                                 (base.CellTemplate as DataGridViewComboBoxCell).DropDownWidth = value;
110                         }
111                 }
112
113                 public FlatStyle FlatStyle {
114                         get { return flatStyle; }
115                         set { flatStyle = value; }
116                 }
117
118                 public DataGridViewComboBoxCell.ObjectCollection Items {
119                         get {
120                                 if (base.CellTemplate == null) {
121                                         throw new InvalidOperationException("CellTemplate is null.");
122                                 }
123                                 return (base.CellTemplate as DataGridViewComboBoxCell).Items;
124                         }
125                 }
126
127                 public int MaxDropDownItems {
128                         get {
129                                 if (base.CellTemplate == null) {
130                                         throw new InvalidOperationException("CellTemplate is null.");
131                                 }
132                                 return (base.CellTemplate as DataGridViewComboBoxCell).MaxDropDownItems;
133                         }
134                         set {
135                                 if (base.CellTemplate == null) {
136                                         throw new InvalidOperationException("CellTemplate is null.");
137                                 }
138                                 (base.CellTemplate as DataGridViewComboBoxCell).MaxDropDownItems = value;
139                         }
140                 }
141
142                 public bool Sorted {
143                         get {
144                                 if (base.CellTemplate == null) {
145                                         throw new InvalidOperationException("CellTemplate is null.");
146                                 }
147                                 return (base.CellTemplate as DataGridViewComboBoxCell).Sorted;
148                         }
149                         set {
150                                 if (base.CellTemplate == null) {
151                                         throw new InvalidOperationException("CellTemplate is null.");
152                                 }
153                                 (base.CellTemplate as DataGridViewComboBoxCell).Sorted = value;
154                         }
155                 }
156
157                 public string ValueMember {
158                         get {
159                                 if (base.CellTemplate == null) {
160                                         throw new InvalidOperationException("CellTemplate is null.");
161                                 }
162                                 return (base.CellTemplate as DataGridViewComboBoxCell).ValueMember;
163                         }
164                         set {
165                                 if (base.CellTemplate == null) {
166                                         throw new InvalidOperationException("CellTemplate is null.");
167                                 }
168                                 (base.CellTemplate as DataGridViewComboBoxCell).ValueMember = value;
169                         }
170                 }
171
172                 public override object Clone () {
173                         DataGridViewComboBoxColumn col = (DataGridViewComboBoxColumn) base.Clone();
174                         col.autoComplete = this.autoComplete;
175                         col.displayStyle = this.displayStyle;
176                         col.displayStyleForCurrentCellsOnly = this.displayStyleForCurrentCellsOnly;
177                         col.flatStyle = this.flatStyle;
178                         col.CellTemplate = (DataGridViewComboBoxCell) this.CellTemplate.Clone();
179                         return col;
180                 }
181
182                 public override string ToString () {
183                         return GetType().Name;
184                 }
185
186         }
187
188 }
189
190 #endif