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.Collections;
30 using System.ComponentModel;
33 namespace System.Windows.Forms {
35 public class DataGridViewComboBoxCell : DataGridViewCell {
37 private bool autoComplete;
38 private object dataSource;
39 private string displayMember;
40 private DataGridViewComboBoxDisplayStyle displayStyle;
41 private bool displayStyleForCurrentCellOnly;
42 private int dropDownWidth;
43 private FlatStyle flatStyle;
44 private ObjectCollection items;
45 private int maxDropDownItems;
47 private string valueMember;
49 public DataGridViewComboBoxCell () : base() {
52 displayStyle = DataGridViewComboBoxDisplayStyle.DropDownButton;
53 displayStyleForCurrentCellOnly = false;
55 flatStyle = FlatStyle.Standard;
56 items = new ObjectCollection(this);
61 public virtual bool AutoComplete {
62 get { return autoComplete; }
63 set { autoComplete = value; }
66 public virtual object DataSource {
67 get { return dataSource; }
69 if (value is IList || value is IListSource || value == null) {
73 throw new Exception("Value is no IList, IListSource or null.");
77 public virtual string DisplayMember {
78 get { return displayMember; }
79 set { displayMember = value; }
82 public DataGridViewComboBoxDisplayStyle DisplayStyle {
83 get { return displayStyle; }
84 set { displayStyle = value; }
87 public bool DisplayStyleForCurrentCellOnly {
88 get { return displayStyleForCurrentCellOnly; }
89 set { displayStyleForCurrentCellOnly = value; }
92 public virtual int DropDownWidth {
93 get { return dropDownWidth; }
96 throw new ArgumentOutOfRangeException("Value is less than 1.");
98 dropDownWidth = value;
102 public override Type EditType {
103 get { return typeof(DataGridViewComboBoxEditingControl); }
106 public FlatStyle FlatStyle {
107 get { return flatStyle; }
109 if (!Enum.IsDefined(typeof(FlatStyle), value)) {
110 throw new InvalidEnumArgumentException("Value is not valid FlatStyle.");
116 public override Type FormattedValueType {
117 get { return typeof(string); }
120 public virtual ObjectCollection Items {
121 get { return items; }
124 public virtual int MaxDropDownItems {
125 get { return maxDropDownItems; }
127 if (value < 1 || value > 100) {
128 throw new ArgumentOutOfRangeException("Value is less than 1 or greater than 100.");
130 maxDropDownItems = value;
134 public virtual bool Sorted {
135 get { return sorted; }
139 throw new ArgumentException("Cannot sort a cell attached to a data source.");
146 public virtual string ValueMember {
147 get { return valueMember; }
148 set { valueMember = value; }
151 public override Type ValueType {
152 get { return typeof(string); }
155 public override object Clone () {
156 DataGridViewComboBoxCell cell = (DataGridViewComboBoxCell) base.Clone();
157 cell.autoComplete = this.autoComplete;
158 cell.dataSource = this.dataSource;
159 cell.displayStyle = this.displayStyle;
160 cell.displayStyleForCurrentCellOnly = this.displayStyleForCurrentCellOnly;
161 cell.dropDownWidth = this.dropDownWidth;
162 cell.flatStyle = this.flatStyle;
163 cell.items.AddRange(this.items);
164 cell.maxDropDownItems = this.maxDropDownItems;
165 cell.sorted = this.sorted;
169 public override void DetachEditingControl () {
170 throw new NotImplementedException();
173 public override void InitializeEditingControl (int rowIndex, object initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle) {
174 throw new NotImplementedException();
177 public override bool KeyEntersEditMode (KeyEventArgs e) {
178 throw new NotImplementedException();
181 public override object ParseFormattedValue (object formattedValue, DataGridViewCellStyle cellStyle, TypeConverter formattedValueTypeConverter, TypeConverter valueTypeConverter) {
182 throw new NotImplementedException();
185 public override string ToString () {
186 throw new NotImplementedException();
189 protected override Rectangle GetContentBounds (Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex) {
190 throw new NotImplementedException();
193 protected override Rectangle GetErrorIconBounds (Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex) {
194 throw new NotImplementedException();
197 protected override object GetFormattedValue (object value, int rowIndex, ref DataGridViewCellStyle cellStyle, TypeConverter valueTypeConverter, TypeConverter formattedValueTypeConverter, DataGridViewDataErrorContexts context) {
198 throw new NotImplementedException();
201 protected override Size GetPreferredSize (Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex, Size constraintSize) {
202 throw new NotImplementedException();
205 protected override void OnDataGridViewChanged () {
206 throw new NotImplementedException();
209 protected override void OnEnter (int rowIndex, bool throughMouseClick) {
210 throw new NotImplementedException();
213 protected override void OnLeave (int rowIndex, bool throughMouseClick) {
214 throw new NotImplementedException();
217 protected override void OnMouseClick (DataGridViewCellMouseEventArgs e) {
218 throw new NotImplementedException();
221 protected override void OnMouseEnter (int rowIndex) {
222 throw new NotImplementedException();
225 protected override void OnMouseLeave (int rowIndex) {
226 throw new NotImplementedException();
229 protected override void OnMouseMove (DataGridViewCellMouseEventArgs e) {
230 throw new NotImplementedException();
233 protected override void Paint (Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementeState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) {
234 throw new NotImplementedException();
237 public class ObjectCollection : IList, ICollection, IEnumerable {
239 private ArrayList list;
241 private DataGridViewComboBoxCell owner;
243 public ObjectCollection (DataGridViewComboBoxCell owner) {
245 list = new ArrayList();
248 public virtual int Count {
249 get { return list.Count; }
252 public virtual bool IsFixedSize {
253 get { return list.IsFixedSize; }
256 public virtual bool IsReadOnly {
257 get { return list.IsReadOnly; }
260 public virtual bool IsSynchronized {
261 get { return list.IsSynchronized; }
264 public virtual object SyncRoot {
265 get { return list.SyncRoot; }
268 public virtual object this [int index] {
269 get { return list[index]; }
270 set { list[index] = value; }
273 public int Add (object item) {
274 return list.Add(item);
277 public void AddRange (ObjectCollection value) {
278 list.AddRange(value.list);
281 public void AddRange (object[] items) {
282 list.AddRange(items);
285 //public sealed void Clear () {
286 public void Clear () {
290 //public sealed bool Contains (object value) {
291 public bool Contains (object value) {
292 return list.Contains(value);
295 public void CopyTo (Array destination, int arrayIndex) {
296 list.CopyTo(destination, arrayIndex);
299 //public sealed IEnumerator GetEnumerator () {
300 public IEnumerator GetEnumerator () {
301 return list.GetEnumerator();
304 //public sealed int IndexOf (object value) {
305 public int IndexOf (object value) {
306 return list.IndexOf(value);
309 //public sealed void Insert (int index, object item) {
310 public void Insert (int index, object item) {
311 list.Insert(index, item);
314 //public sealed void Remove (object value) {
315 public void Remove (object value) {
319 //public sealed void RemoveAt (int index) {
320 public void RemoveAt (int index) {
321 list.RemoveAt(index);