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>
27 using System.ComponentModel;
29 namespace System.Windows.Forms {
31 public class DataGridViewBand : DataGridViewElement, ICloneable, IDisposable {
33 private ContextMenuStrip contextMenuStrip = null;
34 private DataGridViewCellStyle defaultCellStyle;
35 private Type defaultHeaderCellType;
36 private bool displayed;
37 private bool frozen = false;
38 private int index = -1;
39 private bool readOnly = false;
40 private DataGridViewTriState resizable = DataGridViewTriState.NotSet;
41 private bool selected = false;
42 private object tag = null;
43 private bool visible = true;
44 private DataGridViewHeaderCell headerCellCore;
46 private DataGridViewCellStyle inheritedStyle = null;
48 internal DataGridViewBand ()
50 defaultHeaderCellType = typeof (DataGridViewHeaderCell);
51 isRow = this is DataGridViewRow;
60 public virtual ContextMenuStrip ContextMenuStrip {
61 get { return contextMenuStrip; }
62 set { contextMenuStrip = value; }
66 public virtual DataGridViewCellStyle DefaultCellStyle {
68 if (defaultCellStyle == null) {
69 defaultCellStyle = new DataGridViewCellStyle();
71 return defaultCellStyle;
73 set { defaultCellStyle = value; }
77 public Type DefaultHeaderCellType {
78 get { return defaultHeaderCellType; }
80 if (!value.IsSubclassOf(typeof(DataGridViewHeaderCell))) {
81 throw new ArgumentException("Type is not DataGridViewHeaderCell or a derived type.");
83 defaultHeaderCellType = value;
88 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
89 public virtual bool Displayed {
90 get { return displayed; }
93 [DefaultValue (false)]
94 public virtual bool Frozen {
95 get { return frozen; }
97 if (frozen != value) {
100 SetState (State | DataGridViewElementStates.Frozen);
102 SetState (State & ~DataGridViewElementStates.Frozen);
108 public bool HasDefaultCellStyle {
109 get { return (defaultCellStyle != null); }
114 get { return index; }
118 public virtual DataGridViewCellStyle InheritedStyle {
119 get { return inheritedStyle; }
122 [DefaultValue (false)]
123 public virtual bool ReadOnly {
124 get { return readOnly; }
126 if (readOnly != value) {
129 SetState (State | DataGridViewElementStates.ReadOnly);
131 SetState (State & ~DataGridViewElementStates.ReadOnly);
137 public virtual DataGridViewTriState Resizable {
139 if (resizable == DataGridViewTriState.NotSet && DataGridView != null) {
140 return DataGridView.AllowUserToResizeColumns ? DataGridViewTriState.True : DataGridViewTriState.False;
144 if (value != resizable) {
146 if (resizable == DataGridViewTriState.True)
147 SetState (State | DataGridViewElementStates.Resizable);
149 SetState (State & ~DataGridViewElementStates.Resizable);
155 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
156 public virtual bool Selected {
157 get { return selected; }
159 if (DataGridView == null) {
160 throw new InvalidOperationException("Cant select a row non associated with a DataGridView.");
163 DataGridView.SetSelectedRowCoreInternal (Index, value);
165 DataGridView.SetSelectedColumnCoreInternal (Index, value);
170 internal bool SelectedInternal {
175 if (selected != value) {
179 SetState (State | DataGridViewElementStates.Selected);
181 SetState (State & ~DataGridViewElementStates.Selected);
186 internal bool DisplayedInternal {
187 get { return displayed; }
189 if (value != displayed) {
192 SetState (State | DataGridViewElementStates.Displayed);
194 SetState (State & ~DataGridViewElementStates.Displayed);
200 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
206 [DefaultValue (true)]
207 public virtual bool Visible {
208 get { return visible; }
210 if (visible != value) {
213 SetState (State | DataGridViewElementStates.Visible);
215 SetState (State & ~DataGridViewElementStates.Visible);
220 public virtual object Clone ()
222 DataGridViewBand result = new DataGridViewBand();
223 //////////////////////////////
227 //public sealed void Dispose () {
228 public void Dispose ()
232 public override string ToString ()
234 return this.GetType().Name + ": " + index.ToString() + ".";
238 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
239 protected DataGridViewHeaderCell HeaderCellCore {
240 get { return headerCellCore; }
241 set { headerCellCore = value; }
244 protected bool IsRow {
245 get { return isRow; }
248 protected virtual void Dispose (bool disposing)
252 protected override void OnDataGridViewChanged ()
256 internal virtual void SetIndex (int index)