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;
31 namespace System.Windows.Forms {
33 public class DataGridViewBand : DataGridViewElement, ICloneable, IDisposable {
35 private ContextMenuStrip contextMenuStrip = null;
36 private DataGridViewCellStyle defaultCellStyle;
37 private Type defaultHeaderCellType;
38 private bool displayed;
39 private bool frozen = false;
40 private int index = -1;
41 private bool readOnly = false;
42 private DataGridViewTriState resizable = DataGridViewTriState.NotSet;
43 private bool selected = false;
44 private object tag = null;
45 private bool visible = true;
46 private DataGridViewHeaderCell headerCellCore;
48 private DataGridViewCellStyle inheritedStyle = null;
50 internal DataGridViewBand ()
52 defaultHeaderCellType = typeof (DataGridViewHeaderCell);
53 isRow = this is DataGridViewRow;
62 public virtual ContextMenuStrip ContextMenuStrip {
63 get { return contextMenuStrip; }
64 set { contextMenuStrip = value; }
68 public virtual DataGridViewCellStyle DefaultCellStyle {
70 if (defaultCellStyle == null) {
71 defaultCellStyle = new DataGridViewCellStyle();
73 return defaultCellStyle;
75 set { defaultCellStyle = value; }
79 public Type DefaultHeaderCellType {
80 get { return defaultHeaderCellType; }
82 if (value.IsSubclassOf(typeof(DataGridViewHeaderCell))) {
83 throw new ArgumentException("Type is not DataGridViewHeaderCell or a derived type.");
85 defaultHeaderCellType = value;
90 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
91 public virtual bool Displayed {
92 get { return displayed; }
95 [DefaultValue (false)]
96 public virtual bool Frozen {
97 get { return frozen; }
98 set { frozen = value; }
102 public bool HasDefaultCellStyle {
103 get { return (defaultCellStyle != null); }
108 get { return index; }
112 public virtual DataGridViewCellStyle InheritedStyle {
113 get { return inheritedStyle; }
116 [DefaultValue (false)]
117 public virtual bool ReadOnly {
118 get { return readOnly; }
119 set { readOnly = value; }
123 public virtual DataGridViewTriState Resizable {
125 if (resizable == DataGridViewTriState.NotSet && DataGridView != null) {
126 return DataGridView.AllowUserToResizeColumns ? DataGridViewTriState.True : DataGridViewTriState.False;
129 set { resizable = value; }
133 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
134 public virtual bool Selected {
135 get { return selected; }
137 if (DataGridView == null) {
138 throw new InvalidOperationException("Cant select a row non associated with a DataGridView.");
141 DataGridView.SetSelectedRowCoreInternal (Index, value);
143 DataGridView.SetSelectedColumnCoreInternal (Index, value);
148 internal bool SelectedInternal {
158 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
164 [DefaultValue (true)]
165 public virtual bool Visible {
166 get { return visible; }
167 set { visible = value; }
170 public virtual object Clone ()
172 DataGridViewBand result = new DataGridViewBand();
173 //////////////////////////////
177 //public sealed void Dispose () {
178 public void Dispose ()
182 public override string ToString ()
184 return this.GetType().Name + ": " + index.ToString() + ".";
188 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
189 protected DataGridViewHeaderCell HeaderCellCore {
190 get { return headerCellCore; }
191 set { headerCellCore = value; }
194 protected bool IsRow {
195 get { return isRow; }
198 protected virtual void Dispose (bool disposing)
202 protected override void OnDataGridViewChanged ()
206 internal virtual void SetIndex (int index)