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; }
99 if (frozen != value) {
102 SetState (State | DataGridViewElementStates.Frozen);
104 SetState (State & ~DataGridViewElementStates.Frozen);
110 public bool HasDefaultCellStyle {
111 get { return (defaultCellStyle != null); }
116 get { return index; }
120 public virtual DataGridViewCellStyle InheritedStyle {
121 get { return inheritedStyle; }
124 [DefaultValue (false)]
125 public virtual bool ReadOnly {
126 get { return readOnly; }
128 if (readOnly != value) {
131 SetState (State | DataGridViewElementStates.ReadOnly);
133 SetState (State & ~DataGridViewElementStates.ReadOnly);
139 public virtual DataGridViewTriState Resizable {
141 if (resizable == DataGridViewTriState.NotSet && DataGridView != null) {
142 return DataGridView.AllowUserToResizeColumns ? DataGridViewTriState.True : DataGridViewTriState.False;
146 if (value != resizable) {
148 if (resizable == DataGridViewTriState.True)
149 SetState (State | DataGridViewElementStates.Resizable);
151 SetState (State & ~DataGridViewElementStates.Resizable);
157 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
158 public virtual bool Selected {
159 get { return selected; }
161 if (DataGridView == null) {
162 throw new InvalidOperationException("Cant select a row non associated with a DataGridView.");
165 DataGridView.SetSelectedRowCoreInternal (Index, value);
167 DataGridView.SetSelectedColumnCoreInternal (Index, value);
172 internal bool SelectedInternal {
177 if (selected != value) {
181 SetState (State | DataGridViewElementStates.Selected);
183 SetState (State & ~DataGridViewElementStates.Selected);
188 internal bool DisplayedInternal {
189 get { return displayed; }
191 if (value != displayed) {
194 SetState (State | DataGridViewElementStates.Displayed);
196 SetState (State & ~DataGridViewElementStates.Displayed);
202 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
208 [DefaultValue (true)]
209 public virtual bool Visible {
210 get { return visible; }
212 if (visible != value) {
215 SetState (State | DataGridViewElementStates.Visible);
217 SetState (State & ~DataGridViewElementStates.Visible);
222 public virtual object Clone ()
224 DataGridViewBand result = new DataGridViewBand();
225 //////////////////////////////
229 //public sealed void Dispose () {
230 public void Dispose ()
234 public override string ToString ()
236 return this.GetType().Name + ": " + index.ToString() + ".";
240 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
241 protected DataGridViewHeaderCell HeaderCellCore {
242 get { return headerCellCore; }
243 set { headerCellCore = value; }
246 protected bool IsRow {
247 get { return isRow; }
250 protected virtual void Dispose (bool disposing)
254 protected override void OnDataGridViewChanged ()
258 internal virtual void SetIndex (int index)