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 // Jordi Mas i Hernandez <jordi@ximian.com>
31 using System.ComponentModel;
33 using System.Runtime.InteropServices;
34 using System.Collections;
36 namespace System.Windows.Forms
38 [DefaultEvent("Navigate")]
39 [DefaultProperty("DataSource")]
40 [Designer("System.Windows.Forms.Design.DataGridDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
41 public class DataGrid : Control, ISupportInitialize, IDataGridEditingService
45 public enum HitTestType
57 public sealed class HitTestInfo
59 public static readonly HitTestInfo Nowhere = null;
61 #region Local Variables
64 private HitTestType type;
65 #endregion // Local Variables
67 #region Private Constructors
68 internal HitTestInfo ()
72 type = HitTestType.None;
77 #region Public Instance Properties
79 get { return column; }
84 public DataGrid.HitTestType Type {
87 #endregion //Public Instance Properties
89 public override bool Equals (object o)
91 if (!(o is HitTestInfo))
94 HitTestInfo obj = (HitTestInfo) o;
95 return (obj.Column == column && obj.Row == row && obj.Type ==type);
98 public override int GetHashCode ()
103 public override string ToString ()
105 return base.ToString ();
110 #region Local Variables
111 private static readonly Color def_alternating_backcolor = ThemeEngine.Current.DataGridAlternatingBackColor;
112 private static readonly Color def_background_color = ThemeEngine.Current.DataGridBackgroundColor;
113 private static readonly Color def_caption_backcolor = ThemeEngine.Current.DataGridCaptionBackColor;
114 private static readonly Color def_caption_forecolor = ThemeEngine.Current.DataGridCaptionForeColor;
115 private static readonly Color def_gridline_color = ThemeEngine.Current.DataGridGridLineColor;
116 private static readonly Color def_header_backcolor = ThemeEngine.Current.DataGridHeaderBackColor;
117 private static readonly Font def_header_font = ThemeEngine.Current.DefaultFont;
118 private static readonly Color def_header_forecolor = ThemeEngine.Current.DataGridHeaderForeColor;
119 private static readonly Color def_link_hovercolor = ThemeEngine.Current.DataGridLinkHoverColor;
120 private static readonly Color def_parentrowsback_color = ThemeEngine.Current.DataGridParentRowsBackColor;
121 private static readonly Color def_parentrowsfore_color = ThemeEngine.Current.DataGridParentRowsForeColor;
122 private static readonly Color def_selection_backcolor = ThemeEngine.Current.DataGridSelectionBackColor;
123 private static readonly Color def_selection_forecolor = ThemeEngine.Current.DataGridSelectionForeColor;
124 private static readonly Color def_link_color = ThemeEngine.Current.DataGridLinkColor;
126 private bool allow_navigation;
127 private bool allow_sorting;
128 private Color alternating_backcolor;
129 private Color background_color;
130 internal BorderStyle border_style;
131 private Color caption_backcolor;
132 private Font caption_font;
133 private Color caption_forecolor;
134 private string caption_text;
135 internal bool caption_visible;
136 internal bool columnheaders_visible;
137 private object datasource;
138 private string datamember;
139 private int firstvisible_column;
140 private bool flatmode;
141 private Color gridline_color;
142 private DataGridLineStyle gridline_style;
143 private Color header_backcolor;
144 private Color header_forecolor;
145 private Font header_font;
146 private Color link_color;
147 private Color link_hovercolor;
148 private Color parentrowsback_color;
149 private Color parentrowsfore_color;
150 internal bool parentrows_visible;
151 private int preferredcolumn_width;
152 private int preferredrow_height;
153 private bool _readonly;
154 internal bool rowheaders_visible;
155 private Color selection_backcolor;
156 private Color selection_forecolor;
157 private int rowheaders_width;
158 internal int visiblecolumn_count;
159 internal int visiblerow_count;
160 internal int first_visiblecolumn;
161 private int currentrow_index;
162 private GridTableStylesCollection styles_collection;
163 private DataGridParentRowsLabelStyle parentrowslabel_style;
164 private DataGridCell current_cell;
165 private Color forecolor;
166 private Color backcolor;
167 private DataGridTableStyle default_style;
168 private DataGridTableStyle current_style;
169 internal HScrollBar horiz_scrollbar;
170 internal VScrollBar vert_scrollbar;
171 private DataGridDrawing grid_drawing;
172 internal int first_visiblerow;
173 internal int horz_pixeloffset;
174 #endregion // Local Variables
176 #region Public Constructors
179 allow_navigation = true;
180 allow_sorting = true;
181 alternating_backcolor = def_alternating_backcolor;
182 background_color = def_background_color;
183 border_style = BorderStyle.Fixed3D;
184 caption_backcolor = def_caption_backcolor;
186 caption_forecolor = def_caption_forecolor;
187 caption_text = string.Empty;
188 caption_visible = true;
189 columnheaders_visible = true;
191 datamember = string.Empty;
192 firstvisible_column = 0;
194 gridline_color = def_gridline_color;
195 gridline_style = DataGridLineStyle.Solid;
196 header_backcolor = def_header_backcolor;
197 header_forecolor = def_header_forecolor;
198 header_font = def_header_font;
199 link_color = def_link_color;
200 link_hovercolor = def_link_hovercolor;
201 parentrowsback_color = def_parentrowsback_color;
202 parentrowsfore_color = def_parentrowsfore_color;
203 parentrows_visible = false; // should be true (temp)
204 preferredcolumn_width = ThemeEngine.Current.DataGridPreferredColumnWidth;
205 preferredrow_height = 16;
207 rowheaders_visible = true;
208 selection_backcolor = def_selection_backcolor;
209 selection_forecolor = def_selection_forecolor;
210 rowheaders_width = 35;
211 visiblecolumn_count = 0;
212 visiblerow_count = 0;
213 current_cell = new DataGridCell ();
214 currentrow_index = -1;
215 first_visiblerow = 0;
216 first_visiblecolumn = 0;
217 horz_pixeloffset = 0;
218 forecolor = SystemColors.WindowText;
219 parentrowslabel_style = DataGridParentRowsLabelStyle.Both;
220 backcolor = SystemColors.Window;
222 default_style = new DataGridTableStyle (true);
223 styles_collection = new GridTableStylesCollection (this);
224 styles_collection.CollectionChanged += new CollectionChangeEventHandler (OnTableStylesCollectionChanged);
226 CurrentTableStyle = default_style;
228 horiz_scrollbar = new HScrollBar ();
229 horiz_scrollbar.Scroll += new ScrollEventHandler (OnHorizontalScrollEvent);
230 vert_scrollbar = new VScrollBar ();
231 vert_scrollbar.ValueChanged += new EventHandler (OnVerticalScrollEvent);
232 grid_drawing = new DataGridDrawing (this);
234 SetStyle (ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
238 #endregion // Public Constructor
240 #region Public Instance Properties
243 public bool AllowNavigation {
245 return allow_navigation;
249 if (allow_navigation != value) {
250 allow_navigation = value;
251 OnAllowNavigationChanged (EventArgs.Empty);
257 public bool AllowSorting {
259 return allow_sorting;
263 if (allow_sorting != value) {
264 allow_sorting = value;
269 public Color AlternatingBackColor {
271 return alternating_backcolor;
275 if (alternating_backcolor != value) {
276 alternating_backcolor = value;
282 public Color BackColor {
287 if (backcolor != value) {
294 public Color BackgroundColor {
296 return background_color;
299 if (background_color != value) {
300 background_color = value;
301 OnBackgroundColorChanged (EventArgs.Empty);
308 [EditorBrowsable(EditorBrowsableState.Never)]
309 public Image BackgroundImage {
311 return base.BackgroundImage;
315 base.BackgroundImage = value;
320 [DefaultValue(BorderStyle.Fixed3D)]
321 public BorderStyle BorderStyle {
327 if (border_style != value) {
328 border_style = value;
329 grid_drawing.CalcGridAreas ();
330 OnBorderStyleChanged (EventArgs.Empty);
336 public Color CaptionBackColor {
338 return caption_backcolor;
342 if (caption_backcolor != value) {
343 caption_backcolor = value;
344 grid_drawing.InvalidateCaption ();
351 public Font CaptionFont {
353 if (caption_font == null) {
361 if (caption_font != null && caption_font.Equals (value)) {
365 caption_font = value;
366 grid_drawing.CalcGridAreas ();
371 public Color CaptionForeColor {
373 return caption_forecolor;
377 if (caption_forecolor != value) {
378 caption_forecolor = value;
379 grid_drawing.InvalidateCaption ();
386 public string CaptionText {
392 if (caption_text != value) {
393 caption_text = value;
394 grid_drawing.InvalidateCaption ();
400 public bool CaptionVisible {
402 return caption_visible;
406 if (caption_visible != value) {
407 caption_visible = value;
408 grid_drawing.CalcGridAreas ();
410 OnCaptionVisibleChanged (EventArgs.Empty);
416 public bool ColumnHeadersVisible {
418 return columnheaders_visible;
422 if (columnheaders_visible != value) {
423 columnheaders_visible = value;
424 grid_drawing.CalcGridAreas ();
431 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
432 public DataGridCell CurrentCell {
438 if (!current_cell.Equals (value)) {
439 current_cell = value;
446 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
447 public int CurrentRowIndex {
449 return currentrow_index;
453 if (currentrow_index != value) {
454 currentrow_index = value;
461 [EditorBrowsable(EditorBrowsableState.Never)]
462 public override Cursor Cursor {
472 [Editor ("System.Windows.Forms.Design.DataMemberListEditor, System.Design, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Drawing.Design.UITypeEditor, System.Drawing, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
473 public string DataMember {
474 get { return datamember; }
476 if (SetDataMember (datamember)) {
484 [RefreshProperties(RefreshProperties.Repaint)]
485 [TypeConverter("System.Windows.Forms.Design.DataSourceConverter, System.Design, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
486 public object DataSource {
492 if (SetDataSource (value)) {
499 protected override Size DefaultSize {
501 return new Size (130, 80);
506 public int FirstVisibleColumn {
508 return firstvisible_column;
512 [DefaultValue(false)]
513 public bool FlatMode {
519 if (flatmode != value) {
521 OnFlatModeChanged (EventArgs.Empty);
527 public Color ForeColor {
533 if (forecolor != value) {
535 OnForeColorChanged (EventArgs.Empty);
541 public Color GridLineColor {
543 return gridline_color;
547 if (value == Color.Empty) {
548 throw new ArgumentNullException ("Color.Empty value is invalid.");
551 if (gridline_color != value) {
552 gridline_color = value;
558 [DefaultValue(DataGridLineStyle.Solid)]
559 public DataGridLineStyle GridLineStyle {
561 return gridline_style;
565 if (gridline_style != value) {
566 gridline_style = value;
572 public Color HeaderBackColor {
574 return header_backcolor;
578 if (value == Color.Empty) {
579 throw new ArgumentNullException ("Color.Empty value is invalid.");
582 if (header_backcolor != value) {
583 header_backcolor = value;
589 public Font HeaderFont {
595 if (header_font != null && !header_font.Equals (value)) {
602 public Color HeaderForeColor {
604 return header_forecolor;
608 if (header_forecolor != value) {
609 header_forecolor = value;
615 protected ScrollBar HorizScrollBar {
617 return horiz_scrollbar;
621 public object this [DataGridCell cell] {
623 throw new NotImplementedException ();
627 throw new NotImplementedException ();
631 public object this [int rowIndex, int columnIndex] {
633 throw new NotImplementedException ();
637 throw new NotImplementedException ();
641 public Color LinkColor {
646 if (link_color != value) {
655 [EditorBrowsable(EditorBrowsableState.Never)]
656 public Color LinkHoverColor {
658 return link_hovercolor;
662 if (link_hovercolor != value) {
663 link_hovercolor = value;
670 [EditorBrowsable(EditorBrowsableState.Advanced)]
671 protected internal CurrencyManager ListManager {
673 if (BindingContext == null || DataSource == null) {
677 return (CurrencyManager) BindingContext [DataSource, DataMember];
681 throw new NotSupportedException ("Operation is not supported.");
685 public Color ParentRowsBackColor {
687 return parentrowsback_color;
691 if (parentrowsback_color != value) {
692 parentrowsback_color = value;
693 if (parentrows_visible) {
700 public Color ParentRowsForeColor {
702 return parentrowsfore_color;
706 if (parentrowsfore_color != value) {
707 parentrowsfore_color = value;
708 if (parentrows_visible) {
715 [DefaultValue(DataGridParentRowsLabelStyle.Both)]
716 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
717 public DataGridParentRowsLabelStyle ParentRowsLabelStyle {
719 return parentrowslabel_style;
723 if (parentrowslabel_style != value) {
724 parentrowslabel_style = value;
725 if (parentrows_visible) {
729 OnParentRowsLabelStyleChanged (EventArgs.Empty);
735 public bool ParentRowsVisible {
737 return parentrows_visible;
741 if (parentrows_visible != value) {
742 parentrows_visible = value;
743 grid_drawing.CalcGridAreas ();
745 OnParentRowsVisibleChanged (EventArgs.Empty);
750 // Settting this property seems to have no effect.
752 [TypeConverter(typeof(DataGridPreferredColumnWidthTypeConverter))]
753 public int PreferredColumnWidth {
755 return preferredcolumn_width;
760 throw new ArgumentException ("PreferredColumnWidth is less than 0");
763 if (preferredcolumn_width != value) {
764 preferredcolumn_width = value;
770 public int PreferredRowHeight {
772 return preferredrow_height;
776 if (preferredrow_height != value) {
777 preferredrow_height = value;
778 grid_drawing.CalcGridAreas ();
784 [DefaultValue(false)]
785 public bool ReadOnly {
791 if (_readonly != value) {
793 OnReadOnlyChanged (EventArgs.Empty);
800 public bool RowHeadersVisible {
802 return rowheaders_visible;
806 if (rowheaders_visible != value) {
807 rowheaders_visible = value;
808 grid_drawing.CalcGridAreas ();
815 public int RowHeaderWidth {
817 return rowheaders_width;
821 if (rowheaders_width != value) {
822 rowheaders_width = value;
823 grid_drawing.CalcGridAreas ();
829 public Color SelectionBackColor {
831 return selection_backcolor;
835 if (selection_backcolor != value) {
836 selection_backcolor = value;
842 public Color SelectionForeColor {
844 return selection_forecolor;
848 if (selection_forecolor != value) {
849 selection_forecolor = value;
855 public override ISite Site {
865 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
866 public GridTableStylesCollection TableStyles {
867 get { return styles_collection; }
872 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
873 [EditorBrowsable(EditorBrowsableState.Never)]
874 public override string Text {
884 [EditorBrowsable(EditorBrowsableState.Advanced)]
885 protected ScrollBar VertScrollBar {
887 return vert_scrollbar;
892 public int VisibleColumnCount {
894 return visiblecolumn_count;
898 // Calculated at DataGridDrawing.CalcRowsHeaders
900 public int VisibleRowCount {
902 return visiblerow_count;
906 #endregion // Public Instance Properties
908 #region Private Instance Properties
909 internal DataGridTableStyle CurrentTableStyle {
911 return current_style;
914 current_style = value;
918 internal int FirstVisibleRow {
919 get { return first_visiblerow; }
920 set { first_visiblerow = value;}
923 internal int RowsCount {
925 if (ListManager != null) {
926 return ListManager.Count;
933 internal int RowHeight {
935 if (preferredrow_height > Font.Height + 3) {
936 return preferredrow_height;
939 return Font.Height + 3;
944 #endregion Private Instance Properties
946 #region Public Instance Methods
948 public virtual bool BeginEdit (DataGridColumnStyle gridColumn, int rowNumber)
950 throw new NotImplementedException ();
953 public virtual void BeginInit ()
959 protected virtual void CancelEditing ()
964 public void Collapse (int row)
969 protected internal virtual void ColumnStartedEditing (Control editingControl)
974 protected internal virtual void ColumnStartedEditing (Rectangle bounds)
979 protected override AccessibleObject CreateAccessibilityInstance ()
981 return base.CreateAccessibilityInstance ();
984 protected virtual DataGridColumnStyle CreateGridColumn (PropertyDescriptor prop)
986 return CreateGridColumn (prop, false);
989 protected virtual DataGridColumnStyle CreateGridColumn (PropertyDescriptor prop, bool isDefault)
991 throw new NotImplementedException ();
994 protected override void Dispose (bool disposing)
996 base.Dispose (disposing);
999 public virtual bool EndEdit (DataGridColumnStyle gridColumn, int rowNumber, bool shouldAbort)
1001 throw new NotImplementedException ();
1004 public virtual void EndInit ()
1009 public void Expand (int row)
1014 public Rectangle GetCellBounds (DataGridCell dgc)
1016 throw new NotImplementedException ();
1019 public Rectangle GetCellBounds (int row, int col)
1021 throw new NotImplementedException ();
1024 public Rectangle GetCurrentCellBounds ()
1026 throw new NotImplementedException ();
1029 protected virtual string GetOutputTextDelimiter ()
1031 throw new NotImplementedException ();
1034 protected virtual void GridHScrolled (object sender, ScrollEventArgs se)
1039 protected virtual void GridVScrolled (object sender, ScrollEventArgs se)
1044 public HitTestInfo HitTest (Point position)
1046 throw new NotImplementedException ();
1049 public HitTestInfo HitTest (int x, int y)
1051 throw new NotImplementedException ();
1054 public bool IsExpanded (int rowNumber)
1056 throw new NotImplementedException ();
1059 public bool IsSelected (int row)
1061 throw new NotImplementedException ();
1064 public void NavigateBack ()
1069 public void NavigateTo (int rowNumber, string relationName)
1074 protected virtual void OnAllowNavigationChanged (EventArgs e)
1076 if (AllowNavigationChanged != null) {
1077 AllowNavigationChanged (this, e);
1081 protected void OnBackButtonClicked (object sender, EventArgs e)
1083 if (BackButtonClick != null) {
1084 BackButtonClick (sender, e);
1088 protected override void OnBackColorChanged (EventArgs e)
1090 base.OnBackColorChanged (e);
1093 protected virtual void OnBackgroundColorChanged (EventArgs e)
1095 if (BackgroundColorChanged != null) {
1096 BackgroundColorChanged (this, e);
1100 protected override void OnBindingContextChanged( EventArgs e)
1102 base.OnBindingContextChanged (e);
1105 protected virtual void OnBorderStyleChanged (EventArgs e)
1107 if (BorderStyleChanged != null) {
1108 BorderStyleChanged (this, e);
1112 protected virtual void OnCaptionVisibleChanged (EventArgs e)
1114 if (CaptionVisibleChanged != null) {
1115 CaptionVisibleChanged (this, e);
1119 protected virtual void OnCurrentCellChanged (EventArgs e)
1121 if (CurrentCellChanged != null) {
1122 CurrentCellChanged (this, e);
1126 protected virtual void OnDataSourceChanged (EventArgs e)
1128 if (DataSourceChanged != null) {
1129 DataSourceChanged (this, e);
1133 protected override void OnEnter (EventArgs e)
1138 protected virtual void OnFlatModeChanged (EventArgs e)
1140 if (FlatModeChanged != null) {
1141 FlatModeChanged (this, e);
1145 protected override void OnFontChanged (EventArgs e)
1147 base.OnFontChanged (e);
1148 grid_drawing.CalcGridAreas ();
1151 protected override void OnForeColorChanged (EventArgs e)
1153 base.OnForeColorChanged (e);
1156 protected override void OnHandleCreated (EventArgs e)
1158 base.OnHandleCreated (e);
1159 grid_drawing.CalcGridAreas ();
1162 protected override void OnHandleDestroyed (EventArgs e)
1164 base.OnHandleDestroyed (e);
1167 protected override void OnKeyDown (KeyEventArgs ke)
1169 base.OnKeyDown (ke);
1172 protected override void OnKeyPress (KeyPressEventArgs kpe)
1174 base.OnKeyPress (kpe);
1177 protected override void OnLayout (LayoutEventArgs levent)
1179 base.OnLayout (levent);
1182 protected override void OnLeave (EventArgs e)
1187 protected override void OnMouseDown (MouseEventArgs e)
1189 base.OnMouseDown (e);
1192 protected override void OnMouseLeave (EventArgs e)
1194 base.OnMouseLeave (e);
1197 protected override void OnMouseMove (MouseEventArgs e)
1199 base.OnMouseMove (e);
1202 protected override void OnMouseUp (MouseEventArgs e)
1207 protected override void OnMouseWheel (MouseEventArgs e)
1209 base.OnMouseWheel (e);
1212 protected void OnNavigate (NavigateEventArgs e)
1214 if (Navigate != null) {
1219 protected override void OnPaint (PaintEventArgs pe)
1221 grid_drawing.OnPaint (pe);
1224 protected override void OnPaintBackground (PaintEventArgs ebe)
1226 base.OnPaintBackground (ebe);
1229 protected virtual void OnParentRowsLabelStyleChanged (EventArgs e)
1231 if (ParentRowsLabelStyleChanged != null) {
1232 ParentRowsLabelStyleChanged (this, e);
1236 protected virtual void OnParentRowsVisibleChanged (EventArgs e)
1238 if (ParentRowsVisibleChanged != null) {
1239 ParentRowsVisibleChanged (this, e);
1243 protected virtual void OnReadOnlyChanged (EventArgs e)
1245 if (ReadOnlyChanged != null) {
1246 ReadOnlyChanged (this, e);
1250 protected override void OnResize (EventArgs e)
1255 protected void OnRowHeaderClick (EventArgs e)
1257 if (RowHeaderClick != null) {
1258 RowHeaderClick (this, e);
1262 protected void OnScroll (EventArgs e)
1264 if (Scroll != null) {
1269 protected void OnShowParentDetailsButtonClicked (object sender, EventArgs e)
1271 if (ShowParentDetailsButtonClick != null) {
1272 ShowParentDetailsButtonClick (sender, e);
1276 protected override bool ProcessDialogKey (Keys keyData)
1278 return base.ProcessDialogKey (keyData);
1281 protected bool ProcessGridKey (KeyEventArgs ke)
1283 throw new NotImplementedException ();
1286 protected override bool ProcessKeyPreview (ref Message m)
1288 return base.ProcessKeyPreview (ref m);
1291 protected bool ProcessTabKey (Keys keyData)
1293 throw new NotImplementedException ();
1296 public void ResetAlternatingBackColor ()
1298 alternating_backcolor = def_alternating_backcolor;
1301 public override void ResetBackColor ()
1303 background_color = def_background_color;
1306 public override void ResetForeColor ()
1308 base.ResetForeColor ();
1311 public void ResetGridLineColor ()
1313 gridline_color = def_gridline_color;
1316 public void ResetHeaderBackColor ()
1318 header_backcolor = def_header_backcolor;
1321 public void ResetHeaderFont ()
1323 header_font = def_header_font;
1326 public void ResetHeaderForeColor ()
1328 header_forecolor = def_header_forecolor;
1331 public void ResetLinkColor ()
1333 link_color = def_link_color;
1336 public void ResetLinkHoverColor ()
1338 link_hovercolor = def_link_hovercolor;
1341 protected void ResetSelection ()
1346 public void ResetSelectionBackColor ()
1348 selection_backcolor = def_selection_backcolor;
1351 public void ResetSelectionForeColor ()
1353 selection_forecolor = def_selection_forecolor;
1356 public void Select (int row)
1361 public void SetDataBinding (object dataSource, string dataMember)
1363 if (SetDataSource (dataSource) == false && SetDataMember (dataMember) == false) {
1367 SetNewDataSource ();
1370 protected virtual bool ShouldSerializeAlternatingBackColor ()
1372 return (alternating_backcolor != def_alternating_backcolor);
1375 protected virtual bool ShouldSerializeBackgroundColor ()
1377 return (background_color != def_background_color);
1380 protected virtual bool ShouldSerializeCaptionBackColor ()
1382 return (caption_backcolor != def_caption_backcolor);
1385 protected virtual bool ShouldSerializeCaptionForeColor ()
1387 return (caption_forecolor != def_caption_forecolor);
1390 protected virtual bool ShouldSerializeGridLineColor ()
1392 return (gridline_color != def_gridline_color);
1395 protected virtual bool ShouldSerializeHeaderBackColor ()
1397 return (header_backcolor != def_header_backcolor);
1400 protected bool ShouldSerializeHeaderFont ()
1402 return (header_font != def_header_font);
1405 protected virtual bool ShouldSerializeHeaderForeColor ()
1407 return (header_forecolor != def_header_forecolor);
1410 protected virtual bool ShouldSerializeLinkHoverColor ()
1412 return (link_hovercolor != def_link_hovercolor);
1415 protected virtual bool ShouldSerializeParentRowsBackColor ()
1417 return (parentrowsback_color != def_parentrowsback_color);
1420 protected virtual bool ShouldSerializeParentRowsForeColor ()
1422 return (parentrowsback_color != def_parentrowsback_color);
1425 protected bool ShouldSerializePreferredRowHeight ()
1427 return (parentrowsfore_color != def_parentrowsfore_color);
1430 protected bool ShouldSerializeSelectionBackColor ()
1432 return (selection_backcolor != def_selection_backcolor);
1435 protected virtual bool ShouldSerializeSelectionForeColor ()
1437 return (selection_forecolor != def_selection_forecolor);
1440 public void SubObjectsSiteChange (bool site)
1445 public void UnSelect (int row)
1449 #endregion // Public Instance Methods
1451 #region Private Instance Methods
1453 internal void CalcAreasAndInvalidate ()
1455 grid_drawing.CalcGridAreas ();
1459 private bool SetDataMember (string member)
1461 if (member == datamember) {
1465 datamember = member;
1469 private bool SetDataSource (object source)
1471 if (datasource != null && datasource.Equals (source)) {
1475 if (source != null && source as IListSource != null && source as IList != null) {
1476 throw new Exception ("Wrong complex data binding source");
1479 datasource = source;
1480 OnDataSourceChanged (EventArgs.Empty);
1484 private void SetNewDataSource ()
1486 // Create Table Style
1487 // Create columns Styles
1490 current_style.DataGrid = this;
1491 current_style.CreateColumnsForTable ();
1492 grid_drawing.CalcGridAreas ();
1495 private void OnHorizontalScrollEvent (object sender, ScrollEventArgs e)
1497 if (horiz_scrollbar.Value == horz_pixeloffset ||
1498 e.Type == ScrollEventType.EndScroll) {
1502 Rectangle invalidate = new Rectangle ();
1503 Rectangle invalidate_column = new Rectangle ();
1505 if (horiz_scrollbar.Value > horz_pixeloffset) { // ScrollRight
1506 int pixels = horiz_scrollbar.Value - horz_pixeloffset;
1509 invalidate_column.X = grid_drawing.ColumnsHeadersArea.X + grid_drawing.ColumnsHeadersArea.Width - pixels;
1510 invalidate_column.Y = grid_drawing.ColumnsHeadersArea.Y;
1511 invalidate_column.Width = pixels;
1512 invalidate_column.Height = grid_drawing.ColumnsHeadersArea.Height;
1513 XplatUI.ScrollWindow (Handle, grid_drawing.ColumnsHeadersArea, -pixels, 0, false);
1516 invalidate.X = grid_drawing.CellsArea.X + grid_drawing.CellsArea.Width - pixels;
1517 invalidate.Y = grid_drawing.CellsArea.Y;
1518 invalidate.Width = pixels;
1519 invalidate.Height = grid_drawing.CellsArea.Height;
1520 XplatUI.ScrollWindow (Handle, grid_drawing.CellsArea, -pixels, 0, false);
1523 int pixels = horz_pixeloffset - horiz_scrollbar.Value;
1526 invalidate_column.X = grid_drawing.ColumnsHeadersArea.X;
1527 invalidate_column.Y = grid_drawing.ColumnsHeadersArea.Y;
1528 invalidate_column.Width = pixels;
1529 invalidate_column.Height = grid_drawing.ColumnsHeadersArea.Height;
1530 XplatUI.ScrollWindow (Handle, grid_drawing.ColumnsHeadersArea, pixels, 0, false);
1533 invalidate.X = grid_drawing.CellsArea.X;
1534 invalidate.Y = grid_drawing.CellsArea.Y;
1535 invalidate.Width = pixels;
1536 invalidate.Height = grid_drawing.CellsArea.Height;
1537 XplatUI.ScrollWindow (Handle, grid_drawing.CellsArea, pixels, 0, false);
1540 horz_pixeloffset = horiz_scrollbar.Value;
1541 grid_drawing.UpdateVisibleColumn ();
1542 Invalidate (invalidate_column);
1543 Invalidate (invalidate);
1547 private void OnTableStylesCollectionChanged (object sender, CollectionChangeEventArgs e)
1549 Console.WriteLine ("Datagrid.TableStyles Collection Changed {0}, null {1}", e.Action,
1552 TODO: What's up if there are columns in the incoming TableStyle
1555 CurrentTableStyle = (DataGridTableStyle)e.Element;
1558 case CollectionChangeAction.Add: {
1559 ((DataGridTableStyle) e.Element).CreateColumnsForTable ();
1562 case CollectionChangeAction.Remove:
1564 case CollectionChangeAction.Refresh:
1573 private void OnVerticalScrollEvent (object sender, EventArgs e)
1575 if (vert_scrollbar.Value == first_visiblerow) {
1579 Rectangle invalidate = new Rectangle ();
1581 if (vert_scrollbar.Value > first_visiblerow ) { // Scrolldown
1582 int scrolled_rows = vert_scrollbar.Value - first_visiblerow;
1583 int pixels = scrolled_rows * RowHeight;
1585 invalidate.X = grid_drawing.CellsArea.X;
1586 invalidate.Y = grid_drawing.CellsArea.Y + grid_drawing.CellsArea.Height - pixels;
1587 invalidate.Width = grid_drawing.CellsArea.Width;
1588 invalidate.Height = pixels;
1590 XplatUI.ScrollWindow (Handle, grid_drawing.CellsArea, 0, -pixels, false);
1592 } else { // ScrollUp
1593 int scrolled_rows = first_visiblerow - vert_scrollbar.Value;
1594 int pixels = scrolled_rows * RowHeight;
1596 invalidate.X = grid_drawing.CellsArea.X;
1597 invalidate.Y = grid_drawing.CellsArea.Y;
1598 invalidate.Width = grid_drawing.CellsArea.Width;
1599 invalidate.Height = pixels;
1601 XplatUI.ScrollWindow (Handle, grid_drawing.CellsArea, 0, pixels, false);
1604 first_visiblerow = vert_scrollbar.Value;
1605 grid_drawing.UpdateVisibleRowCount ();
1606 Invalidate (invalidate);
1607 Invalidate (grid_drawing.RowsHeadersArea);
1610 #endregion Private Instance Methods
1614 public event EventHandler AllowNavigationChanged;
1615 public event EventHandler BackButtonClick;
1616 public event EventHandler BackgroundColorChanged;
1619 [EditorBrowsable(EditorBrowsableState.Never)]
1620 public new event EventHandler BackgroundImageChanged;
1622 public event EventHandler BorderStyleChanged;
1623 public event EventHandler CaptionVisibleChanged;
1624 public event EventHandler CurrentCellChanged;
1627 [EditorBrowsable(EditorBrowsableState.Never)]
1628 public new event EventHandler CursorChanged;
1630 public event EventHandler DataSourceChanged;
1631 public event EventHandler FlatModeChanged;
1632 public event NavigateEventHandler Navigate;
1633 public event EventHandler ParentRowsLabelStyleChanged;
1634 public event EventHandler ParentRowsVisibleChanged;
1635 public event EventHandler ReadOnlyChanged;
1636 protected event EventHandler RowHeaderClick;
1637 public event EventHandler Scroll;
1638 public event EventHandler ShowParentDetailsButtonClick;
1641 [EditorBrowsable(EditorBrowsableState.Never)]
1642 public new event EventHandler TextChanged;
1643 #endregion // Events