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;
32 namespace System.Windows.Forms {
33 public class DataGridViewHeaderCell : DataGridViewCell {
35 private ButtonState buttonState;
37 public DataGridViewHeaderCell ()
39 buttonState = ButtonState.Normal;
43 public override bool Displayed {
44 get { return base.Displayed; }
47 public override Type FormattedValueType {
48 get { return typeof(string); } //base.FormattedValueType; }
52 public override bool Frozen {
53 get { return base.Frozen; }
57 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
58 public override bool ReadOnly {
59 get { return base.ReadOnly; }
60 set { base.ReadOnly = value; }
64 public override bool Resizable {
65 get { return base.Resizable; }
69 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
70 public override bool Selected {
71 get { return base.Selected; }
72 set { base.Selected = value; }
75 public override Type ValueType {
76 get { return base.ValueType; }
77 set { base.ValueType = value; }
81 public override bool Visible {
82 get { return base.Visible; }
85 public override object Clone ()
87 DataGridViewHeaderCell result = new DataGridViewHeaderCell();
91 protected override void Dispose (bool disposing)
95 public override ContextMenuStrip GetInheritedContextMenuStrip (int rowIndex)
97 if (DataGridView == null)
100 if (ContextMenuStrip != null)
101 return ContextMenuStrip;
102 if (DataGridView.ContextMenuStrip != null)
103 return DataGridView.ContextMenuStrip;
108 public override DataGridViewElementStates GetInheritedState (int rowIndex)
110 DataGridViewElementStates result;
112 result = DataGridViewElementStates.ResizableSet | State;
117 public override string ToString ()
119 return string.Format ("DataGridViewHeaderCell {{ ColumnIndex={0}, RowIndex={1} }}", ColumnIndex, RowIndex);
122 protected override Size GetSize (int rowIndex)
124 if (DataGridView == null && rowIndex != -1)
125 throw new ArgumentOutOfRangeException ("rowIndex");
126 if (OwningColumn != null && rowIndex != -1)
127 throw new ArgumentOutOfRangeException ("rowIndex");
128 if (OwningRow != null && (rowIndex < 0 || rowIndex >= DataGridView.Rows.Count))
129 throw new ArgumentOutOfRangeException ("rowIndex");
130 if (OwningColumn == null && OwningRow == null && rowIndex != -1)
131 throw new ArgumentOutOfRangeException ("rowIndex");
132 if (OwningRow != null && OwningRow.Index != rowIndex)
133 throw new ArgumentException ("rowIndex");
135 if (DataGridView == null)
136 return new Size (-1, -1);
138 if (this is DataGridViewTopLeftHeaderCell)
139 return new Size (DataGridView.RowHeadersWidth, DataGridView.ColumnHeadersHeight);
140 if (this is DataGridViewColumnHeaderCell)
141 return new Size (100, DataGridView.ColumnHeadersHeight);
142 if (this is DataGridViewRowHeaderCell)
143 return new Size (DataGridView.RowHeadersWidth, 22);
148 protected override object GetValue (int rowIndex)
150 return base.GetValue (rowIndex);
153 protected override bool MouseDownUnsharesRow (DataGridViewCellMouseEventArgs e)
155 if (DataGridView == null)
158 if (e.Button == MouseButtons.Left && Application.RenderWithVisualStyles && DataGridView.EnableHeadersVisualStyles)
164 protected override bool MouseEnterUnsharesRow (int rowIndex)
166 if (DataGridView == null)
169 if (Application.RenderWithVisualStyles && DataGridView.EnableHeadersVisualStyles)
175 protected override bool MouseLeaveUnsharesRow (int rowIndex)
177 if (DataGridView == null)
180 if (ButtonState != ButtonState.Normal && Application.RenderWithVisualStyles && DataGridView.EnableHeadersVisualStyles)
186 protected override bool MouseUpUnsharesRow (DataGridViewCellMouseEventArgs e)
188 if (DataGridView == null)
191 if (e.Button == MouseButtons.Left && Application.RenderWithVisualStyles && DataGridView.EnableHeadersVisualStyles)
197 protected override void OnMouseDown (DataGridViewCellMouseEventArgs e)
199 base.OnMouseDown (e);
202 protected override void OnMouseEnter (int rowIndex)
204 base.OnMouseEnter (rowIndex);
207 protected override void OnMouseLeave (int rowIndex)
209 base.OnMouseLeave (rowIndex);
212 protected override void OnMouseUp (DataGridViewCellMouseEventArgs e)
217 protected override void Paint (Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates dataGridViewElementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
219 base.Paint (graphics, clipBounds, cellBounds, rowIndex, dataGridViewElementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
222 protected ButtonState ButtonState {
223 get { return buttonState; }