* TextBoxBase.cs: Use the new SuspendRecalc/ResumeRecalc methods
[mono-project.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / DataGridViewRow.cs
bloba44ea087f1cf17edb9873508a3d1370c1b8107f0
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:
8 //
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
11 //
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)
22 // Author:
23 // Pedro Martínez Juliá <pedromj@gmail.com>
27 #if NET_2_0
29 using System.ComponentModel;
30 using System.Drawing;
31 using System.Runtime.InteropServices;
33 namespace System.Windows.Forms {
35 // XXX [TypeConverter (typeof (DataGridRowConverter))]
36 public class DataGridViewRow : DataGridViewBand {
38 private AccessibleObject accessibilityObject;
39 private DataGridViewCellCollection cells;
40 private ContextMenuStrip contextMenuStrip;
41 private object dataBoundItem;
42 private int dividerHeight;
43 private string errorText;
44 private DataGridViewRowHeaderCell headerCell;
45 private int height;
46 private int minimumHeight;
48 public DataGridViewRow ()
50 cells = new DataGridViewCellCollection(this);
51 minimumHeight = 3;
52 height = -1;
53 headerCell = new DataGridViewRowHeaderCell();
56 [Browsable (false)]
57 public AccessibleObject AccessibilityObject {
58 get { return accessibilityObject; }
61 [Browsable (false)]
62 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
63 public DataGridViewCellCollection Cells {
64 get { return cells; }
67 [DefaultValue (null)]
68 public override ContextMenuStrip ContextMenuStrip {
69 get { return contextMenuStrip; }
70 set {
71 if (contextMenuStrip != value) {
72 contextMenuStrip = value;
73 if (DataGridView != null) {
74 DataGridView.OnRowContextMenuStripChanged(new DataGridViewRowEventArgs(this));
80 [Browsable (false)]
81 [EditorBrowsable (EditorBrowsableState.Advanced)]
82 public object DataBoundItem {
83 get { return dataBoundItem; }
86 [Browsable (true)]
87 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
88 [NotifyParentProperty (true)]
89 public override DataGridViewCellStyle DefaultCellStyle {
90 get { return base.DefaultCellStyle; }
91 set {
92 if (DefaultCellStyle != value) {
93 base.DefaultCellStyle = value;
94 if (DataGridView != null) {
95 DataGridView.OnRowDefaultCellStyleChanged(new DataGridViewRowEventArgs(this));
101 [Browsable (false)]
102 public override bool Displayed {
103 get { return base.Displayed; }
106 [DefaultValue (0)]
107 [NotifyParentProperty (true)]
108 public int DividerHeight {
109 get { return dividerHeight; }
110 set { dividerHeight = value; }
113 [DefaultValue ("")]
114 [NotifyParentProperty (true)]
115 public string ErrorText {
116 get { return errorText; }
117 set {
118 if (errorText != value) {
119 errorText = value;
120 if (DataGridView != null) {
121 DataGridView.OnRowErrorTextChanged(new DataGridViewRowEventArgs(this));
127 [Browsable (false)]
128 public override bool Frozen {
129 get { return base.Frozen; }
130 set { base.Frozen = value; }
133 [Browsable (false)]
134 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
135 public DataGridViewRowHeaderCell HeaderCell {
136 get { return headerCell; }
137 set {
138 if (headerCell != value) {
139 headerCell = value;
140 if (DataGridView != null) {
141 DataGridView.OnRowHeaderCellChanged(new DataGridViewRowEventArgs(this));
147 [DefaultValue (22)]
148 [NotifyParentProperty (true)]
149 public int Height {
150 get {
151 if (height < 0) {
152 if (DefaultCellStyle != null && DefaultCellStyle.Font != null) {
153 return DefaultCellStyle.Font.Height + 9;
155 if (InheritedStyle != null && InheritedStyle.Font != null) {
156 return InheritedStyle.Font.Height + 9;
158 return System.Windows.Forms.Control.DefaultFont.Height + 9;
160 return height;
162 set {
163 if (height != value) {
164 if (height < minimumHeight) {
165 throw new ArgumentOutOfRangeException("Height can't be less than MinimumHeight.");
167 height = value;
168 if (DataGridView != null) {
169 DataGridView.OnRowHeightChanged(new DataGridViewRowEventArgs(this));
175 public override DataGridViewCellStyle InheritedStyle {
176 get {
177 if (DataGridView == null) {
178 return DefaultCellStyle;
180 else {
181 if (DefaultCellStyle == null) {
182 return DataGridView.DefaultCellStyle;
184 else {
185 DataGridViewCellStyle style = (DataGridViewCellStyle) DefaultCellStyle.Clone();
186 /////// Combination with dataGridView.DefaultCellStyle
187 return style;
193 [Browsable (false)]
194 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
195 public bool IsNewRow {
196 get {
197 if (DataGridView != null && DataGridView.Rows[DataGridView.Rows.Count - 1] == this) {
198 return true;
200 return false;
204 [Browsable (false)]
205 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
206 public int MinimumHeight {
207 get { return minimumHeight; }
208 set {
209 if (minimumHeight != value) {
210 if (value < 2 || value > Int32.MaxValue) {
211 throw new ArgumentOutOfRangeException("MinimumHeight should be between 2 and Int32.MaxValue.");
213 minimumHeight = value;
214 if (DataGridView != null) {
215 DataGridView.OnRowMinimumHeightChanged(new DataGridViewRowEventArgs(this));
221 [Browsable (true)]
222 [DefaultValue (false)]
223 [NotifyParentProperty (true)]
224 public override bool ReadOnly {
225 get { return base.ReadOnly; }
226 set { base.ReadOnly = value; }
229 [NotifyParentProperty (true)]
230 public override DataGridViewTriState Resizable {
231 get { return base.Resizable; }
232 set { base.Resizable = value; }
235 public override bool Selected {
236 get {
237 if (Index == -1) {
238 throw new InvalidOperationException("The row is a shared row.");
240 if (DataGridView == null) {
241 throw new InvalidOperationException("The row has not been added to a DataGridView control.");
243 return base.Selected;
245 set {
246 if (Index == -1) {
247 throw new InvalidOperationException("The row is a shared row.");
249 if (DataGridView == null) {
250 throw new InvalidOperationException("The row has not been added to a DataGridView control.");
252 base.Selected = value;
253 foreach (DataGridViewCell cell in cells) {
254 cell.Selected = value;
259 public override DataGridViewElementStates State {
260 get { return base.State; }
263 [Browsable (false)]
264 public override bool Visible {
265 get { return base.Visible; }
266 set {
267 if (IsNewRow && value == false) {
268 throw new InvalidOperationException("Cant make invisible a new row.");
270 base.Visible = value;
274 [EditorBrowsable (EditorBrowsableState.Advanced)]
275 public virtual DataGridViewAdvancedBorderStyle AdjustRowHeaderBorderStyle (DataGridViewAdvancedBorderStyle dataGridViewAdvancedBorderStyleInput, DataGridViewAdvancedBorderStyle dataGridViewAdvancedBorderStylePlaceholder, bool singleVerticalBorderAdded, bool singleHorizontalBorderAdded, bool isFirstDisplayedRow, bool isLastVisibleRow)
277 throw new NotImplementedException();
280 public override object Clone ()
282 DataGridViewRow row = (DataGridViewRow) MemberwiseClone();
283 row.cells = new DataGridViewCellCollection(row);
284 foreach (DataGridViewCell cell in cells) {
285 row.cells.Add(cell.Clone() as DataGridViewCell);
287 return row;
290 public void CreateCells (DataGridView dataGridView)
292 if (dataGridView == null) {
293 throw new ArgumentNullException("DataGridView is null.");
295 if (dataGridView.Rows.Contains(this)) {
296 throw new InvalidOperationException("The row already exists in the DataGridView.");
298 DataGridViewCellCollection newCellCollection = new DataGridViewCellCollection(this);
299 foreach (DataGridViewColumn column in dataGridView.Columns) {
300 if (column.CellTemplate == null) {
301 throw new InvalidOperationException("Cell template not set in column: " + column.Index.ToString() + ".");
303 newCellCollection.Add((DataGridViewCell) column.CellTemplate.Clone());
305 cells = newCellCollection;
308 public void CreateCells (DataGridView dataGridView, params object[] values)
310 if (values == null) {
311 throw new ArgumentNullException("values is null");
313 CreateCells(dataGridView);
314 for (int i = 0; i < values.Length; i++) {
315 cells[i].Value = values[i];
319 public ContextMenuStrip GetContextMenuStrip (int rowIndex)
321 if (rowIndex == -1) {
322 throw new InvalidOperationException("rowIndex is -1");
324 if (rowIndex < 0 || rowIndex >= DataGridView.Rows.Count) {
325 throw new ArgumentOutOfRangeException("rowIndex is out of range");
328 return null; // XXX
331 public string GetErrorText (int rowIndex)
333 return "";
336 public virtual int GetPreferredHeight (int rowIndex, DataGridViewAutoSizeRowMode autoSizeRowMode, bool fixedWidth)
338 throw new NotImplementedException();
341 [EditorBrowsable (EditorBrowsableState.Advanced)]
342 public virtual DataGridViewElementStates GetState (int rowIndex)
344 throw new NotImplementedException();
347 public bool SetValues (params object[] values)
349 if (values == null) {
350 throw new ArgumentNullException("vues is null");
352 if (DataGridView != null && DataGridView.VirtualMode) {
353 throw new InvalidOperationException("DataGridView is operating in virtual mode");
355 /////// COLUMNAS //////////
356 for (int i = 0; i < values.Length; i++) {
357 DataGridViewCell cell = new DataGridViewTextBoxCell();
358 cell.Value = values[i];
359 cells.Add(cell);
362 // XXX
363 return true;
366 public override string ToString ()
368 return this.GetType().Name + ", Band Index: " + base.Index.ToString();
371 protected virtual AccessibleObject CreateAccessibilityInstance ()
373 return new DataGridViewRowAccessibleObject(this);
376 [EditorBrowsable (EditorBrowsableState.Advanced)]
377 protected virtual DataGridViewCellCollection CreateCellsInstance ()
379 cells = new DataGridViewCellCollection(this);
380 return cells;
383 [EditorBrowsable (EditorBrowsableState.Advanced)]
384 protected internal virtual void DrawFocus (Graphics graphics, Rectangle clipBounds, Rectangle bounds, int rowIndex, DataGridViewElementStates rowState, DataGridViewCellStyle cellStyle, bool cellsPaintSelectionBackground)
388 protected internal virtual void Paint (Graphics graphics, Rectangle clipBounds, Rectangle rowBounds, int rowIndex, DataGridViewElementStates rowState, bool isFirstDisplayedRow, bool isLastVisibleRow)
392 [EditorBrowsable (EditorBrowsableState.Advanced)]
393 protected internal virtual void PaintCells (Graphics graphics, Rectangle clipBounds, Rectangle rowBounds, int rowIndex, DataGridViewElementStates rowState, bool isFirstDisplayedRow, bool isLastVisibleRow, DataGridViewPaintParts paintParts)
397 [EditorBrowsable (EditorBrowsableState.Advanced)]
398 protected internal virtual void PaintHeader (Graphics graphics, Rectangle clipBounds, Rectangle rowBounds, int rowIndex, DataGridViewElementStates rowState, bool isFirstDisplayedRow, bool isLastVisibleRow, DataGridViewPaintParts paintParts)
402 internal override void SetDataGridView (DataGridView dataGridView)
404 base.SetDataGridView(dataGridView);
405 headerCell.SetDataGridView(dataGridView);
408 internal override void SetState (DataGridViewElementStates state)
410 if (State != state) {
411 base.SetState(state);
412 if (DataGridView != null) {
413 DataGridView.OnRowStateChanged(this.Index, new DataGridViewRowStateChangedEventArgs(this, state));
418 [ComVisibleAttribute(true)]
419 protected class DataGridViewRowAccessibleObject : AccessibleObject {
421 private DataGridViewRow dataGridViewRow;
423 public DataGridViewRowAccessibleObject ()
427 public DataGridViewRowAccessibleObject (DataGridViewRow row)
429 this.dataGridViewRow = row;
432 public override Rectangle Bounds {
433 get { throw new NotImplementedException(); }
436 public override string DefaultAction {
437 get { return "Edit"; }
440 public override string Name {
441 get { return "Index: " + dataGridViewRow.Index.ToString(); }
444 public DataGridViewRow Owner {
445 get { return dataGridViewRow; }
446 set { dataGridViewRow = value; }
449 public override AccessibleObject Parent {
450 get { return dataGridViewRow.AccessibilityObject; }
453 public override AccessibleRole Role {
454 get { return AccessibleRole.Row; }
457 public override AccessibleStates State {
458 get {
459 if (dataGridViewRow.Selected) {
460 return AccessibleStates.Selected;
462 else {
463 return AccessibleStates.Focused;
468 public override string Value {
469 get {
470 if (dataGridViewRow.Cells.Count == 0) {
471 return "(Create New)";
473 string result = "";
474 foreach (DataGridViewCell cell in dataGridViewRow.Cells) {
475 result += cell.AccessibilityObject.Value;
477 return result;
481 public override AccessibleObject GetChild (int index) {
482 throw new NotImplementedException();
485 public override int GetChildCount () {
486 throw new NotImplementedException();
489 public override AccessibleObject GetFocused () {
490 return null;
493 public override AccessibleObject GetSelected () {
494 return null;
497 public override AccessibleObject Navigate (AccessibleNavigation navigationDirection) {
498 switch (navigationDirection) {
499 case AccessibleNavigation.Right:
500 break;
501 case AccessibleNavigation.Left:
502 break;
503 case AccessibleNavigation.Next:
504 break;
505 case AccessibleNavigation.Previous:
506 break;
507 case AccessibleNavigation.Up:
508 break;
509 case AccessibleNavigation.Down:
510 break;
511 default:
512 return null;
514 return null;
517 public override void Select (AccessibleSelection flags) {
518 switch (flags) {
519 case AccessibleSelection.TakeFocus:
520 dataGridViewRow.DataGridView.Focus();
521 break;
522 case AccessibleSelection.TakeSelection:
523 //dataGridViewRow.Focus();
524 break;
525 case AccessibleSelection.AddSelection:
526 dataGridViewRow.DataGridView.SelectedRows.InternalAdd(dataGridViewRow);
527 break;
528 case AccessibleSelection.RemoveSelection:
529 dataGridViewRow.DataGridView.SelectedRows.InternalRemove(dataGridViewRow);
530 break;
542 #endif