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>
26 using System.ComponentModel;
29 namespace System.Windows.Forms {
30 public class DataGridViewHeaderCell : DataGridViewCell {
32 private ButtonState buttonState;
34 public DataGridViewHeaderCell ()
36 buttonState = ButtonState.Normal;
40 public override bool Displayed {
41 get { return base.Displayed; }
44 public override Type FormattedValueType {
45 get { return typeof(string); } //base.FormattedValueType; }
49 public override bool Frozen {
50 get { return base.Frozen; }
54 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
55 public override bool ReadOnly {
56 get { return base.ReadOnly; }
57 set { base.ReadOnly = value; }
61 public override bool Resizable {
62 get { return base.Resizable; }
66 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
67 public override bool Selected {
68 get { return base.Selected; }
69 set { base.Selected = value; }
72 public override Type ValueType {
73 get { return base.ValueType; }
74 set { base.ValueType = value; }
78 public override bool Visible {
79 get { return base.Visible; }
82 public override object Clone ()
84 DataGridViewHeaderCell result = new DataGridViewHeaderCell();
88 protected override void Dispose (bool disposing)
92 public override ContextMenuStrip GetInheritedContextMenuStrip (int rowIndex)
94 if (DataGridView == null)
97 if (ContextMenuStrip != null)
98 return ContextMenuStrip;
99 if (DataGridView.ContextMenuStrip != null)
100 return DataGridView.ContextMenuStrip;
105 public override DataGridViewElementStates GetInheritedState (int rowIndex)
107 DataGridViewElementStates result;
109 result = DataGridViewElementStates.ResizableSet | State;
114 public override string ToString ()
116 return string.Format ("DataGridViewHeaderCell {{ ColumnIndex={0}, RowIndex={1} }}", ColumnIndex, RowIndex);
119 protected override Size GetSize (int rowIndex)
121 if (DataGridView == null && rowIndex != -1)
122 throw new ArgumentOutOfRangeException ("rowIndex");
123 if (OwningColumn != null && rowIndex != -1)
124 throw new ArgumentOutOfRangeException ("rowIndex");
125 if (OwningRow != null && (rowIndex < 0 || rowIndex >= DataGridView.Rows.Count))
126 throw new ArgumentOutOfRangeException ("rowIndex");
127 if (OwningColumn == null && OwningRow == null && rowIndex != -1)
128 throw new ArgumentOutOfRangeException ("rowIndex");
129 if (OwningRow != null && OwningRow.Index != rowIndex)
130 throw new ArgumentException ("rowIndex");
132 if (DataGridView == null)
133 return new Size (-1, -1);
135 if (this is DataGridViewTopLeftHeaderCell)
136 return new Size (DataGridView.RowHeadersWidth, DataGridView.ColumnHeadersHeight);
137 if (this is DataGridViewColumnHeaderCell)
138 return new Size (100, DataGridView.ColumnHeadersHeight);
139 if (this is DataGridViewRowHeaderCell)
140 return new Size (DataGridView.RowHeadersWidth, 22);
145 protected override object GetValue (int rowIndex)
147 return base.GetValue (rowIndex);
150 protected override bool MouseDownUnsharesRow (DataGridViewCellMouseEventArgs e)
152 if (DataGridView == null)
155 if (e.Button == MouseButtons.Left && Application.RenderWithVisualStyles && DataGridView.EnableHeadersVisualStyles)
161 protected override bool MouseEnterUnsharesRow (int rowIndex)
163 if (DataGridView == null)
166 if (Application.RenderWithVisualStyles && DataGridView.EnableHeadersVisualStyles)
172 protected override bool MouseLeaveUnsharesRow (int rowIndex)
174 if (DataGridView == null)
177 if (ButtonState != ButtonState.Normal && Application.RenderWithVisualStyles && DataGridView.EnableHeadersVisualStyles)
183 protected override bool MouseUpUnsharesRow (DataGridViewCellMouseEventArgs e)
185 if (DataGridView == null)
188 if (e.Button == MouseButtons.Left && Application.RenderWithVisualStyles && DataGridView.EnableHeadersVisualStyles)
194 protected override void OnMouseDown (DataGridViewCellMouseEventArgs e)
196 base.OnMouseDown (e);
199 protected override void OnMouseEnter (int rowIndex)
201 base.OnMouseEnter (rowIndex);
204 protected override void OnMouseLeave (int rowIndex)
206 base.OnMouseLeave (rowIndex);
209 protected override void OnMouseUp (DataGridViewCellMouseEventArgs e)
214 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)
216 base.Paint (graphics, clipBounds, cellBounds, rowIndex, dataGridViewElementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
219 protected ButtonState ButtonState {
220 get { return buttonState; }