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>
30 using System.ComponentModel;
33 namespace System.Windows.Forms {
35 public class DataGridViewCheckBoxCell : DataGridViewCell, IDataGridViewEditingCell {
37 private object editingCellFormattedValue;
38 private bool editingCellValueChanged;
39 private object falseValue;
40 private FlatStyle flatStyle;
41 private object indeterminateValue;
42 private bool threeState;
43 private object trueValue;
44 private Type valueType;
46 public DataGridViewCheckBoxCell () {
47 editingCellValueChanged = false;
49 flatStyle = FlatStyle.Standard;
50 indeterminateValue = null;
56 public DataGridViewCheckBoxCell (bool threeState) : this() {
59 public virtual object EditingCellFormattedValue {
60 get { return editingCellFormattedValue; }
62 if (FormattedValueType == null || value == null || value.GetType() != FormattedValueType || !(value is Boolean) || !(value is CheckState)) {
63 throw new ArgumentException("Cannot set this property.");
65 editingCellFormattedValue = value;
69 public virtual bool EditingCellValueChanged {
70 get { return editingCellValueChanged; }
71 set { editingCellValueChanged = value; }
74 public override Type EditType {
78 public object FalseValue {
79 get { return falseValue; }
80 set { falseValue = value; }
83 public FlatStyle FlatStyle {
84 get { return flatStyle; }
86 if (!Enum.IsDefined(typeof(FlatStyle), value)) {
87 throw new InvalidEnumArgumentException("Value is not valid FlatStyle.");
89 if (value == FlatStyle.Popup) {
90 throw new Exception("FlatStyle cannot be set to Popup in this control.");
95 public override Type FormattedValueType {
98 return typeof(CheckState);
100 return typeof(Boolean);
104 public object IndeterminateValue {
105 get { return indeterminateValue; }
106 set { indeterminateValue = value; }
109 public bool ThreeState {
110 get { return threeState; }
111 set { threeState = value; }
114 public object TrueValue {
115 get { return trueValue; }
116 set { trueValue = value; }
119 public override Type ValueType {
121 if (valueType == null) {
122 if (OwningColumn != null) {
123 return OwningColumn.ValueType;
126 return typeof(CheckState);
128 return typeof(Boolean);
132 set { valueType = value; }
135 public override object Clone () {
136 DataGridViewCheckBoxCell cell = (DataGridViewCheckBoxCell) base.Clone();
137 cell.editingCellValueChanged = this.editingCellValueChanged;
138 cell.falseValue = this.falseValue;
139 cell.flatStyle = this.flatStyle;
140 cell.indeterminateValue = this.indeterminateValue;
141 cell.threeState = this.threeState;
142 cell.trueValue = this.trueValue;
143 cell.valueType = this.valueType;
147 public virtual object GetEditingCellFormattedValue (DataGridViewDataErrorContexts context) {
148 if (FormattedValueType == null) {
149 throw new InvalidOperationException("FormattedValueType is null.");
151 if ((context & DataGridViewDataErrorContexts.ClipboardContent) != 0) {
152 return Convert.ToString(Value);
155 return (CheckState) Value;
157 return (Boolean) Value;
160 public override object ParseFormattedValue (object formattedValue, DataGridViewCellStyle cellStyle, TypeConverter formattedValueTypeConverter, TypeConverter valueTypeConverter) {
161 if (cellStyle == null) {
162 throw new ArgumentNullException("CellStyle is null");
164 if (FormattedValueType == null) {
165 throw new FormatException("FormattedValueType is null.");
167 if (formattedValue == null || formattedValue.GetType() != FormattedValueType) {
168 throw new ArgumentException("FormattedValue is null or is not instance of FormattedValueType.");
170 throw new NotImplementedException();
173 public virtual void PrepareEditingCellForEdit (bool selectAll) {
176 public override string ToString () {
177 return GetType().Name + ": RowIndex: " + RowIndex.ToString() + "; ColumnIndex: " + ColumnIndex.ToString() + ";";
180 protected override bool ContentClickUnsharesRow (DataGridViewCellEventArgs e) {
181 return this.IsInEditMode;
184 //protected override bool ContentDoubleClickUnsaresRow (DataGridViewCellEventArgs e) {
185 protected bool ContentDoubleClickUnsaresRow (DataGridViewCellEventArgs e) {
186 return this.IsInEditMode;
189 protected override AccessibleObject CreateAccessibilityInstance () {
190 return new DataGridViewCheckBoxCellAccessibleObject(this);
193 protected override Rectangle GetContentBounds (Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex) {
194 throw new NotImplementedException();
197 protected override Rectangle GetErrorIconBounds (Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex) {
198 throw new NotImplementedException();
201 //protected override object GetFormttedValue (object value, int rowIndex, ref DataGridViewCellStyle cellStyle, TypeConverter valueTypeConverter, TypeConverter formattedValueTypeConverter, DataGridViewDataErrorContexts context) {
202 protected object GetFormttedValue (object value, int rowIndex, ref DataGridViewCellStyle cellStyle, TypeConverter valueTypeConverter, TypeConverter formattedValueTypeConverter, DataGridViewDataErrorContexts context) {
203 if (DataGridView == null) {
206 throw new NotImplementedException();
209 protected override Size GetPreferredSize (Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex, Size constraintSize) {
210 throw new NotImplementedException();
213 protected override object GetValue (int rowIndex) {
214 throw new NotImplementedException();
217 protected override bool KeyDownUnsharesRow (KeyEventArgs e, int rowIndex) {
218 // true if the user pressed the SPACE key without modifier keys; otherwise, false
219 throw new NotImplementedException();
222 protected override bool KeyUpUnsharesRow (KeyEventArgs e, int rowIndex) {
223 // true if the user released the SPACE key; otherwise false
224 throw new NotImplementedException();
228 protected override bool MouseDownUnsharesRow (DataGridViewCellMouseEventArgs e) {
229 return (e.Button == MouseButtons.Left);
232 protected override bool MouseEnterUnsharesRow (int rowIndex) {
233 // true if the cell was the last cell receiving a mouse click; otherwise, false.
234 throw new NotImplementedException();
237 protected override bool MouseLeaveUnsharesRow (int rowIndex) {
238 // true if the button displayed by the cell is in the pressed state; otherwise, false.
239 throw new NotImplementedException();
242 protected override bool MouseUpUnsharesRow (DataGridViewCellMouseEventArgs e) {
243 // true if the mouse up was caused by the release of the left mouse button; otherwise false.
244 throw new NotImplementedException();
247 protected override void OnContentClick (DataGridViewCellEventArgs e) {
248 throw new NotImplementedException();
251 protected override void OnContentDoubleClick (DataGridViewCellEventArgs e) {
252 throw new NotImplementedException();
255 protected override void OnKeyDown (KeyEventArgs e, int rowIndex) {
256 // when activated by the SPACE key, this method updates the cell's user interface
257 throw new NotImplementedException();
260 protected override void OnKeyUp (KeyEventArgs e, int rowIndex) {
261 // when activated by the SPACE key, this method updates the cell's user interface
262 throw new NotImplementedException();
265 protected override void OnLeave (int rowIndex, bool throughMouseClick) {
266 throw new NotImplementedException();
269 protected override void OnMouseDown (DataGridViewCellMouseEventArgs e) {
270 // if activated by depresing the left mouse button, this method updates the cell's user interface
271 throw new NotImplementedException();
274 protected override void OnMouseEnter (int rowIndex) {
275 throw new NotImplementedException();
278 protected override void OnMouseLeave (int rowIndex) {
279 // if the cell's button is not in its normal state, this method causes the cell's user interface to be updated.
280 throw new NotImplementedException();
283 protected override void OnMouseUp (DataGridViewCellMouseEventArgs e) {
284 // if activated by the left mouse button, this method updates the cell's user interface
285 throw new NotImplementedException();
288 protected override void Paint (Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) {
289 throw new NotImplementedException();
292 protected class DataGridViewCheckBoxCellAccessibleObject : DataGridViewCellAccessibleObject {
294 public DataGridViewCheckBoxCellAccessibleObject (DataGridViewCell owner) : base(owner) {
297 public override string DefaultAction {
299 if (Owner.ReadOnly) {
302 // return "Press to check" if the check box is not selected
303 // and "Press to uncheck" if the check box is selected
304 throw new NotImplementedException();
308 public override void DoDefaultAction () {
309 // change the state of the check box
312 public override int GetChildCount () {