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
;
32 namespace System
.Windows
.Forms
{
34 [Designer ("System.Windows.Forms.Design.DataGridViewComboBoxColumnDesigner, " + Consts
.AssemblySystem_Design
,
35 "System.ComponentModel.Design.IDesigner")]
36 public class DataGridViewComboBoxColumn
: DataGridViewColumn
38 private bool autoComplete
;
39 private DataGridViewComboBoxDisplayStyle displayStyle
;
40 private bool displayStyleForCurrentCellOnly
;
41 private FlatStyle flatStyle
;
43 public DataGridViewComboBoxColumn ()
45 CellTemplate
= new DataGridViewComboBoxCell();
46 SortMode
= DataGridViewColumnSortMode
.NotSortable
;
48 displayStyle
= DataGridViewComboBoxDisplayStyle
.DropDownButton
;
49 displayStyleForCurrentCellOnly
= false;
54 public bool AutoComplete
{
55 get { return autoComplete; }
56 set { autoComplete = value; }
60 [DesignerSerializationVisibility (DesignerSerializationVisibility
.Hidden
)]
61 public override DataGridViewCell CellTemplate
{
62 get { return base.CellTemplate; }
63 set { base.CellTemplate = value as DataGridViewComboBoxCell; }
66 [AttributeProvider (typeof (IListSource
))]
68 [RefreshProperties (RefreshProperties
.Repaint
)]
69 public object DataSource
{
71 if (base.CellTemplate
== null) {
72 throw new InvalidOperationException("CellTemplate is null.");
74 return (base.CellTemplate
as DataGridViewComboBoxCell
).DataSource
; }
76 if (base.CellTemplate
== null) {
77 throw new InvalidOperationException("CellTemplate is null.");
79 (base.CellTemplate
as DataGridViewComboBoxCell
).DataSource
= value;
83 [Editor ("System.Windows.Forms.Design.DataMemberFieldEditor, " + Consts
.AssemblySystem_Design
,
84 "System.Drawing.Design.UITypeEditor, " + Consts
.AssemblySystem_Drawing
)]
86 [TypeConverter ("System.Windows.Forms.Design.DataMemberFieldConverter, " + Consts
.AssemblySystem_Design
)]
87 public string DisplayMember
{
89 if (base.CellTemplate
== null) {
90 throw new InvalidOperationException("CellTemplate is null.");
92 return (base.CellTemplate
as DataGridViewComboBoxCell
).DisplayMember
;
95 if (base.CellTemplate
== null) {
96 throw new InvalidOperationException("CellTemplate is null.");
98 (base.CellTemplate
as DataGridViewComboBoxCell
).DisplayMember
= value;
102 [DefaultValue (DataGridViewComboBoxDisplayStyle
.DropDownButton
)]
103 public DataGridViewComboBoxDisplayStyle DisplayStyle
{
104 get { return displayStyle; }
105 set { displayStyle = value; }
108 [DefaultValue (false)]
109 public bool DisplayStyleForCurrentCellOnly
{
110 get { return displayStyleForCurrentCellOnly; }
111 set { displayStyleForCurrentCellOnly = value; }
115 public int DropDownWidth
{
117 if (base.CellTemplate
== null) {
118 throw new InvalidOperationException("CellTemplate is null.");
120 return (base.CellTemplate
as DataGridViewComboBoxCell
).DropDownWidth
;
124 throw new ArgumentException("Value is less than 1.");
126 if (base.CellTemplate
== null) {
127 throw new InvalidOperationException("CellTemplate is null.");
129 (base.CellTemplate
as DataGridViewComboBoxCell
).DropDownWidth
= value;
133 [DefaultValue (FlatStyle
.Standard
)]
134 public FlatStyle FlatStyle
{
135 get { return flatStyle; }
136 set { flatStyle = value; }
139 [Editor ("System.Windows.Forms.Design.StringCollectionEditor, " + Consts
.AssemblySystem_Design
,
140 "System.Drawing.Design.UITypeEditor, " + Consts
.AssemblySystem_Drawing
)]
141 [DesignerSerializationVisibility (DesignerSerializationVisibility
.Content
)]
142 public DataGridViewComboBoxCell
.ObjectCollection Items
{
144 if (base.CellTemplate
== null) {
145 throw new InvalidOperationException("CellTemplate is null.");
147 return (base.CellTemplate
as DataGridViewComboBoxCell
).Items
;
152 public int MaxDropDownItems
{
154 if (base.CellTemplate
== null) {
155 throw new InvalidOperationException("CellTemplate is null.");
157 return (base.CellTemplate
as DataGridViewComboBoxCell
).MaxDropDownItems
;
160 if (base.CellTemplate
== null) {
161 throw new InvalidOperationException("CellTemplate is null.");
163 (base.CellTemplate
as DataGridViewComboBoxCell
).MaxDropDownItems
= value;
167 [DefaultValue (false)]
170 if (base.CellTemplate
== null) {
171 throw new InvalidOperationException("CellTemplate is null.");
173 return (base.CellTemplate
as DataGridViewComboBoxCell
).Sorted
;
176 if (base.CellTemplate
== null) {
177 throw new InvalidOperationException("CellTemplate is null.");
179 (base.CellTemplate
as DataGridViewComboBoxCell
).Sorted
= value;
184 [Editor ("System.Windows.Forms.Design.DataMemberFieldEditor, " + Consts
.AssemblySystem_Design
,
185 "System.Drawing.Design.UITypeEditor, " + Consts
.AssemblySystem_Drawing
)]
186 [TypeConverter ("System.Windows.Forms.Design.DataMemberFieldConverter, " + Consts
.AssemblySystem_Design
)]
187 public string ValueMember
{
189 if (base.CellTemplate
== null) {
190 throw new InvalidOperationException("CellTemplate is null.");
192 return (base.CellTemplate
as DataGridViewComboBoxCell
).ValueMember
;
195 if (base.CellTemplate
== null) {
196 throw new InvalidOperationException("CellTemplate is null.");
198 (base.CellTemplate
as DataGridViewComboBoxCell
).ValueMember
= value;
202 public override object Clone ()
204 DataGridViewComboBoxColumn col
= (DataGridViewComboBoxColumn
) base.Clone();
205 col
.autoComplete
= this.autoComplete
;
206 col
.displayStyle
= this.displayStyle
;
207 col
.displayStyleForCurrentCellOnly
= this.displayStyleForCurrentCellOnly
;
208 col
.flatStyle
= this.flatStyle
;
209 col
.CellTemplate
= (DataGridViewComboBoxCell
) this.CellTemplate
.Clone();
213 public override string ToString ()
215 return GetType().Name
;