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:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
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.
20 // Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
23 // Pedro MartÃnez Juliá <pedromj@gmail.com>
29 using System.ComponentModel;
30 using System.Drawing.Design;
33 namespace System.Windows.Forms {
36 [Designer ("System.Windows.Forms.Design.DataGridViewComboBoxColumnDesigner, " + Consts.AssemblySystem_Design,
37 "System.ComponentModel.Design.IDesigner")]
38 public class DataGridViewComboBoxColumn : DataGridViewColumn
40 private bool autoComplete;
41 private DataGridViewComboBoxDisplayStyle displayStyle;
42 private bool displayStyleForCurrentCellOnly;
43 private FlatStyle flatStyle;
45 public DataGridViewComboBoxColumn ()
47 CellTemplate = new DataGridViewComboBoxCell();
48 SortMode = DataGridViewColumnSortMode.NotSortable;
50 displayStyle = DataGridViewComboBoxDisplayStyle.DropDownButton;
51 displayStyleForCurrentCellOnly = false;
56 public bool AutoComplete {
57 get { return autoComplete; }
58 set { autoComplete = value; }
62 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
63 public override DataGridViewCell CellTemplate {
64 get { return base.CellTemplate; }
65 set { base.CellTemplate = value as DataGridViewComboBoxCell; }
68 [AttributeProvider (typeof (IListSource))]
70 [RefreshProperties (RefreshProperties.Repaint)]
71 public object DataSource {
73 if (base.CellTemplate == null) {
74 throw new InvalidOperationException("CellTemplate is null.");
76 return (base.CellTemplate as DataGridViewComboBoxCell).DataSource; }
78 if (base.CellTemplate == null) {
79 throw new InvalidOperationException("CellTemplate is null.");
81 (base.CellTemplate as DataGridViewComboBoxCell).DataSource = value;
85 [Editor ("System.Windows.Forms.Design.DataMemberFieldEditor, " + Consts.AssemblySystem_Design,
86 "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
88 [TypeConverter ("System.Windows.Forms.Design.DataMemberFieldConverter, " + Consts.AssemblySystem_Design)]
89 public string DisplayMember {
91 if (base.CellTemplate == null) {
92 throw new InvalidOperationException("CellTemplate is null.");
94 return (base.CellTemplate as DataGridViewComboBoxCell).DisplayMember;
97 if (base.CellTemplate == null) {
98 throw new InvalidOperationException("CellTemplate is null.");
100 (base.CellTemplate as DataGridViewComboBoxCell).DisplayMember = value;
104 [DefaultValue (DataGridViewComboBoxDisplayStyle.DropDownButton)]
105 public DataGridViewComboBoxDisplayStyle DisplayStyle {
106 get { return displayStyle; }
107 set { displayStyle = value; }
110 [DefaultValue (false)]
111 public bool DisplayStyleForCurrentCellOnly {
112 get { return displayStyleForCurrentCellOnly; }
113 set { displayStyleForCurrentCellOnly = value; }
117 public int DropDownWidth {
119 if (base.CellTemplate == null) {
120 throw new InvalidOperationException("CellTemplate is null.");
122 return (base.CellTemplate as DataGridViewComboBoxCell).DropDownWidth;
126 throw new ArgumentException("Value is less than 1.");
128 if (base.CellTemplate == null) {
129 throw new InvalidOperationException("CellTemplate is null.");
131 (base.CellTemplate as DataGridViewComboBoxCell).DropDownWidth = value;
135 [DefaultValue (FlatStyle.Standard)]
136 public FlatStyle FlatStyle {
137 get { return flatStyle; }
138 set { flatStyle = value; }
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 {
146 if (base.CellTemplate == null) {
147 throw new InvalidOperationException("CellTemplate is null.");
149 return (base.CellTemplate as DataGridViewComboBoxCell).Items;
154 public int MaxDropDownItems {
156 if (base.CellTemplate == null) {
157 throw new InvalidOperationException("CellTemplate is null.");
159 return (base.CellTemplate as DataGridViewComboBoxCell).MaxDropDownItems;
162 if (base.CellTemplate == null) {
163 throw new InvalidOperationException("CellTemplate is null.");
165 (base.CellTemplate as DataGridViewComboBoxCell).MaxDropDownItems = value;
169 [DefaultValue (false)]
172 if (base.CellTemplate == null) {
173 throw new InvalidOperationException("CellTemplate is null.");
175 return (base.CellTemplate as DataGridViewComboBoxCell).Sorted;
178 if (base.CellTemplate == null) {
179 throw new InvalidOperationException("CellTemplate is null.");
181 (base.CellTemplate as DataGridViewComboBoxCell).Sorted = value;
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 {
191 if (base.CellTemplate == null) {
192 throw new InvalidOperationException("CellTemplate is null.");
194 return (base.CellTemplate as DataGridViewComboBoxCell).ValueMember;
197 if (base.CellTemplate == null) {
198 throw new InvalidOperationException("CellTemplate is null.");
200 (base.CellTemplate as DataGridViewComboBoxCell).ValueMember = value;
204 public override object Clone ()
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();
215 public override string ToString ()
217 return GetType().Name;