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 namespace System.Windows.Forms {
31 public class DataGridViewComboBoxColumn : DataGridViewColumn {
33 private bool autoComplete;
34 private DataGridViewComboBoxDisplayStyle displayStyle;
35 private bool displayStyleForCurrentCellsOnly;
36 private FlatStyle flatStyle;
38 public DataGridViewComboBoxColumn () {
39 CellTemplate = new DataGridViewComboBoxCell();
40 SortMode = DataGridViewColumnSortMode.NotSortable;
42 displayStyle = DataGridViewComboBoxDisplayStyle.DropDownButton;
43 displayStyleForCurrentCellsOnly = false;
46 public bool AutoComplete {
47 get { return autoComplete; }
48 set { autoComplete = value; }
51 public override DataGridViewCell CellTemplate {
52 get { return base.CellTemplate; }
53 set { base.CellTemplate = value as DataGridViewComboBoxCell; }
56 public object DataSource {
58 if (base.CellTemplate == null) {
59 throw new InvalidOperationException("CellTemplate is null.");
61 return (base.CellTemplate as DataGridViewComboBoxCell).DataSource; }
63 if (base.CellTemplate == null) {
64 throw new InvalidOperationException("CellTemplate is null.");
66 (base.CellTemplate as DataGridViewComboBoxCell).DataSource = value;
70 public string DisplayMember {
72 if (base.CellTemplate == null) {
73 throw new InvalidOperationException("CellTemplate is null.");
75 return (base.CellTemplate as DataGridViewComboBoxCell).DisplayMember;
78 if (base.CellTemplate == null) {
79 throw new InvalidOperationException("CellTemplate is null.");
81 (base.CellTemplate as DataGridViewComboBoxCell).DisplayMember = value;
85 public DataGridViewComboBoxDisplayStyle DisplayStyle {
86 get { return displayStyle; }
87 set { displayStyle = value; }
90 public bool DisplayStyleForCurrentCellsOnly {
91 get { return displayStyleForCurrentCellsOnly; }
92 set { displayStyleForCurrentCellsOnly = value; }
95 public int DropDownWidth {
97 if (base.CellTemplate == null) {
98 throw new InvalidOperationException("CellTemplate is null.");
100 return (base.CellTemplate as DataGridViewComboBoxCell).DropDownWidth;
104 throw new ArgumentException("Value is less than 1.");
106 if (base.CellTemplate == null) {
107 throw new InvalidOperationException("CellTemplate is null.");
109 (base.CellTemplate as DataGridViewComboBoxCell).DropDownWidth = value;
113 public FlatStyle FlatStyle {
114 get { return flatStyle; }
115 set { flatStyle = value; }
118 public DataGridViewComboBoxCell.ObjectCollection Items {
120 if (base.CellTemplate == null) {
121 throw new InvalidOperationException("CellTemplate is null.");
123 return (base.CellTemplate as DataGridViewComboBoxCell).Items;
127 public int MaxDropDownItems {
129 if (base.CellTemplate == null) {
130 throw new InvalidOperationException("CellTemplate is null.");
132 return (base.CellTemplate as DataGridViewComboBoxCell).MaxDropDownItems;
135 if (base.CellTemplate == null) {
136 throw new InvalidOperationException("CellTemplate is null.");
138 (base.CellTemplate as DataGridViewComboBoxCell).MaxDropDownItems = value;
144 if (base.CellTemplate == null) {
145 throw new InvalidOperationException("CellTemplate is null.");
147 return (base.CellTemplate as DataGridViewComboBoxCell).Sorted;
150 if (base.CellTemplate == null) {
151 throw new InvalidOperationException("CellTemplate is null.");
153 (base.CellTemplate as DataGridViewComboBoxCell).Sorted = value;
157 public string ValueMember {
159 if (base.CellTemplate == null) {
160 throw new InvalidOperationException("CellTemplate is null.");
162 return (base.CellTemplate as DataGridViewComboBoxCell).ValueMember;
165 if (base.CellTemplate == null) {
166 throw new InvalidOperationException("CellTemplate is null.");
168 (base.CellTemplate as DataGridViewComboBoxCell).ValueMember = value;
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();
182 public override string ToString () {
183 return GetType().Name;