New test.
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / DataGridTableStyle.cs
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:
8 //
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
11 //
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.
19 //
20 // Copyright (c) 2004-2005 Novell, Inc.
21 //
22 // Authors:
23 //
24 //      Peter Bartok <pbartok@novell.com>
25 //      Jordi Mas i Hernandez <jordi@ximian.com>
26 //
27 //
28 // NOT COMPLETE
29 //
30
31 using System.Collections;
32 using System.ComponentModel;
33 using System.Drawing;
34 using System.Runtime.InteropServices;
35 using System.Data;
36 using System.Xml;
37 using System.Runtime.Serialization;
38
39 namespace System.Windows.Forms
40 {
41         [DesignTimeVisible(false)]
42         [ToolboxItem(false)]
43         public class DataGridTableStyle : Component, IDataGridEditingService
44         {
45                 public static DataGridTableStyle DefaultTableStyle = new DataGridTableStyle (true);
46
47                 #region Local Variables
48                 private static readonly Color           def_alternating_backcolor = ThemeEngine.Current.DataGridAlternatingBackColor;
49                 private static readonly Color           def_backcolor = ThemeEngine.Current.DataGridBackColor;
50                 private static readonly Color           def_forecolor = SystemColors.WindowText;
51                 private static readonly Color           def_gridline_color = ThemeEngine.Current.DataGridGridLineColor;
52                 private static readonly Color           def_header_backcolor = ThemeEngine.Current.DataGridHeaderBackColor;
53                 private static readonly Font            def_header_font = ThemeEngine.Current.DefaultFont;
54                 private static readonly Color           def_header_forecolor = ThemeEngine.Current.DataGridHeaderForeColor;
55                 private static readonly Color           def_link_color = ThemeEngine.Current.DataGridLinkColor;
56                 private static readonly Color           def_link_hovercolor = ThemeEngine.Current.DataGridLinkHoverColor;
57                 private static readonly Color           def_selection_backcolor = ThemeEngine.Current.DataGridSelectionBackColor;
58                 private static readonly Color           def_selection_forecolor = ThemeEngine.Current.DataGridSelectionForeColor;
59                 private static readonly int             def_preferredrow_height = ThemeEngine.Current.DefaultFont.Height + 3;
60
61                 private bool                            allow_sorting;
62                 private DataGrid                        datagrid;
63                 private Color                           header_forecolor;
64                 private string                          mapping_name;
65                 private Color                           alternating_backcolor;
66                 private bool                            columnheaders_visible;
67                 private GridColumnStylesCollection      column_styles;
68                 private Color                           gridline_color;
69                 private DataGridLineStyle               gridline_style;
70                 private Color                           header_backcolor;
71                 private Font                            header_font;
72                 private Color                           link_color;
73                 private Color                           link_hovercolor;
74                 private int                             preferredcolumn_width;
75                 private int                             preferredrow_height;
76                 private bool                            _readonly;
77                 private bool                            rowheaders_visible;
78                 private Color                           selection_backcolor;
79                 private Color                           selection_forecolor;
80                 private int                             rowheaders_width;
81                 private Color                           backcolor;
82                 private Color                           forecolor;
83                 private bool                            is_default;
84                 internal ArrayList                      table_relations;
85                 CurrencyManager                         manager;
86                 #endregion      // Local Variables
87
88                 #region Constructors
89                 public DataGridTableStyle ()
90                         : this (false)
91                 {
92                 }
93
94                 public DataGridTableStyle (bool isDefaultTableStyle)
95                 {
96                         is_default = isDefaultTableStyle;
97                         allow_sorting = true;
98                         datagrid = null;
99                         header_forecolor = def_header_forecolor;
100                         mapping_name = string.Empty;
101                         table_relations = new ArrayList ();
102                         column_styles = new GridColumnStylesCollection (this);
103
104                         alternating_backcolor = def_alternating_backcolor;
105                         columnheaders_visible = true;
106                         gridline_color = def_gridline_color;
107                         gridline_style = DataGridLineStyle.Solid;
108                         header_backcolor = def_header_backcolor;
109                         header_font = def_header_font;
110                         link_color = def_link_color;
111                         link_hovercolor = def_link_hovercolor;
112                         preferredcolumn_width = ThemeEngine.Current.DataGridPreferredColumnWidth;
113                         preferredrow_height = ThemeEngine.Current.DefaultFont.Height + 3;
114                         _readonly = false;
115                         rowheaders_visible = true;
116                         selection_backcolor = def_selection_backcolor;
117                         selection_forecolor = def_selection_forecolor;
118                         rowheaders_width = 35;
119                         backcolor = def_backcolor;
120                         forecolor = def_forecolor;
121                 }
122
123                 public DataGridTableStyle (CurrencyManager listManager)
124                         : this (false)
125                 {
126                         manager = listManager;
127                 }
128                 #endregion
129
130                 #region Public Instance Properties
131                 [DefaultValue(true)]
132                 public bool AllowSorting {
133                         get { return allow_sorting; }
134                         set {
135                                 if (is_default)
136                                         throw new ArgumentException ("Cannot change the value of this property on the default DataGridTableStyle.");
137
138                                 if (allow_sorting != value) {
139                                         allow_sorting = value;
140                                         OnAllowSortingChanged (EventArgs.Empty);
141
142                                         if (datagrid != null) {
143                                                 datagrid.Refresh ();
144                                         }
145                                 }
146                         }
147                 }
148
149                 public Color AlternatingBackColor {
150                         get { return alternating_backcolor; }
151                         set {
152                                 if (is_default)
153                                         throw new ArgumentException ("Cannot change the value of this property on the default DataGridTableStyle.");
154
155                                 if (alternating_backcolor != value) {
156                                         alternating_backcolor = value;
157                                         OnAlternatingBackColorChanged (EventArgs.Empty);
158
159                                         if (datagrid != null) {
160                                                 datagrid.Refresh ();
161                                         }
162                                 }
163                         }
164                 }
165
166                 public Color BackColor {
167                         get { return backcolor; }
168                         set {
169                                 if (is_default)
170                                         throw new ArgumentException ("Cannot change the value of this property on the default DataGridTableStyle.");
171
172                                 if (backcolor != value) {
173                                         backcolor = value;
174                                         OnBackColorChanged (EventArgs.Empty);
175
176                                         if (datagrid != null) {
177                                                 datagrid.Refresh ();
178                                         }
179                                 }
180                         }
181                 }
182
183                 [DefaultValue(true)]
184                 public bool ColumnHeadersVisible {
185                         get {
186                                 return columnheaders_visible;
187                         }
188
189                         set {
190                                 if (columnheaders_visible != value) {
191                                         columnheaders_visible = value;
192                                         OnColumnHeadersVisibleChanged (EventArgs.Empty);
193
194                                         if (datagrid != null) {
195                                                 datagrid.Refresh ();
196                                         }
197                                 }
198                         }
199                 }
200
201                 [Browsable(false)]
202                 public virtual DataGrid DataGrid {
203                         get { return datagrid; }
204                         set {
205                                 if (datagrid != value) {
206                                         datagrid = value;
207
208                                         /* now set the value on all our column styles */
209                                         for (int i = 0; i < column_styles.Count; i ++) {
210                                                 column_styles[i].SetDataGridInternal (datagrid);
211                                         }
212                                 }
213                         }
214                 }
215
216                 public Color ForeColor {
217                         get { return forecolor; }
218                         set {
219                                 if (is_default)
220                                         throw new ArgumentException ("Cannot change the value of this property on the default DataGridTableStyle.");
221
222                                 if (forecolor != value) {
223                                         forecolor = value;
224                                         OnForeColorChanged (EventArgs.Empty);
225
226                                         if (datagrid != null) {
227                                                 datagrid.Refresh ();
228                                         }
229                                 }
230                         }
231                 }
232
233                 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
234                 [Localizable(true)]
235                 public virtual GridColumnStylesCollection GridColumnStyles {
236                         get { return column_styles; }
237                 }
238
239                 public Color GridLineColor {
240                         get { return gridline_color; }
241                         set {
242                                 if (is_default)
243                                         throw new ArgumentException ("Cannot change the value of this property on the default DataGridTableStyle.");
244
245                                 if (gridline_color != value) {
246                                         gridline_color = value;
247                                         OnGridLineColorChanged (EventArgs.Empty);
248
249                                         if (datagrid != null) {
250                                                 datagrid.Refresh ();
251                                         }
252                                 }
253                         }
254                 }
255
256                 [DefaultValue(DataGridLineStyle.Solid)]
257                 public DataGridLineStyle GridLineStyle {
258                         get { return gridline_style; }
259                         set {
260                                 if (is_default)
261                                         throw new ArgumentException ("Cannot change the value of this property on the default DataGridTableStyle.");
262
263                                 if (gridline_style != value) {
264                                         gridline_style = value;
265                                         OnGridLineStyleChanged (EventArgs.Empty);
266
267                                         if (datagrid != null) {
268                                                 datagrid.Refresh ();
269                                         }
270                                 }
271                         }
272                 }
273
274                 public Color HeaderBackColor {
275                         get { return header_backcolor; }
276                         set {
277                                 if (is_default)
278                                         throw new ArgumentException ("Cannot change the value of this property on the default DataGridTableStyle.");
279
280                                 if (value == Color.Empty) {
281                                         throw new ArgumentNullException ("Color.Empty value is invalid.");
282                                 }
283
284                                 if (header_backcolor != value) {
285                                         header_backcolor = value;
286                                         OnHeaderBackColorChanged (EventArgs.Empty);
287
288                                         if (datagrid != null) {
289                                                 datagrid.Refresh ();
290                                         }
291                                 }
292                         }
293                 }
294
295                 [AmbientValue(null)]
296                 [Localizable(true)]
297                 public Font HeaderFont {
298                         get { return header_font; }
299                         set {
300                                 if (is_default)
301                                         throw new ArgumentException ("Cannot change the value of this property on the default DataGridTableStyle.");
302
303                                 if (value == null)
304                                         value = def_header_font;
305
306                                 if (header_font != value) {
307                                         header_font = value;
308                                         OnHeaderFontChanged (EventArgs.Empty);
309
310                                         if (datagrid != null) {
311                                                 datagrid.Refresh ();
312                                         }
313                                 }
314                         }
315                 }
316
317                 public Color HeaderForeColor {
318                         get { return header_forecolor; }
319                         set {
320                                 if (is_default)
321                                         throw new ArgumentException ("Cannot change the value of this property on the default DataGridTableStyle.");
322
323                                 if (header_forecolor != value) {
324                                         header_forecolor = value;
325
326                                         if (datagrid != null) {
327                                                 datagrid.Refresh ();
328                                         }
329
330                                         OnHeaderForeColorChanged (EventArgs.Empty);
331                                 }
332                         }
333                 }
334
335                 public Color LinkColor {
336                         get { return link_color; }
337                         set {
338                                 if (is_default)
339                                         throw new ArgumentException ("Cannot change the value of this property on the default DataGridTableStyle.");
340
341                                 if (link_color != value) {
342                                         link_color = value;
343
344                                         if (datagrid != null) {
345                                                 datagrid.Refresh ();
346                                         }
347
348                                         OnLinkColorChanged (EventArgs.Empty);
349                                 }
350                         }
351                 }
352
353                 [ComVisible(false)]
354                 [EditorBrowsable(EditorBrowsableState.Never)]
355                 [Browsable(false)]
356                 public Color LinkHoverColor {
357                         get { return link_hovercolor; }
358                         set {
359                                 if (link_hovercolor != value) {
360                                         link_hovercolor = value;
361                                         OnLinkHoverColorChanged (EventArgs.Empty);
362                                 }
363                         }
364                 }
365
366                 [Editor("System.Windows.Forms.Design.DataGridTableStyleMappingNameEditor, " + Consts.AssemblySystem_Design, typeof(System.Drawing.Design.UITypeEditor))]
367                 public string MappingName {
368                         get { return mapping_name; }
369                         set {
370                                 if (value == null)
371                                         value = "";
372
373                                 if (mapping_name != value) {
374                                         mapping_name = value;
375                                         OnMappingNameChanged (EventArgs.Empty);
376                                 }
377                         }
378                 }
379
380                 [DefaultValue(75)]
381                 [TypeConverter(typeof(DataGridPreferredColumnWidthTypeConverter))]
382                 [Localizable(true)]
383                 public int PreferredColumnWidth {
384                         get { return preferredcolumn_width; }
385                         set {
386                                 if (is_default)
387                                         throw new ArgumentException ("Cannot change the value of this property on the default DataGridTableStyle.");
388
389                                 if (value < 0) {
390                                         throw new ArgumentException ("PreferredColumnWidth is less than 0");
391                                 }
392
393                                 if (preferredcolumn_width != value) {
394                                         preferredcolumn_width = value;
395                                         OnPreferredColumnWidthChanged (EventArgs.Empty);
396                                 }
397                         }
398                 }
399
400                 [Localizable(true)]
401                 public int PreferredRowHeight {
402                         get { return preferredrow_height; }
403                         set {
404                                 if (is_default)
405                                         throw new ArgumentException ("Cannot change the value of this property on the default DataGridTableStyle.");
406
407                                 if (preferredrow_height != value) {
408                                         preferredrow_height = value;
409                                         OnPreferredRowHeightChanged (EventArgs.Empty);
410                                 }
411                         }
412                 }
413
414                 [DefaultValue(false)]
415                 public virtual bool ReadOnly {
416                         get { return _readonly; }
417                         set {
418                                 if (_readonly != value) {
419                                         _readonly = value;
420                                         OnReadOnlyChanged (EventArgs.Empty);
421                                 }
422                         }
423                 }
424
425                 [DefaultValue(true)]
426                 public bool RowHeadersVisible {
427                         get { return rowheaders_visible; }
428                         set {
429                                 if (rowheaders_visible != value) {
430                                         rowheaders_visible = value;
431                                         OnRowHeadersVisibleChanged (EventArgs.Empty);
432                                 }
433                         }
434                 }
435
436                 [DefaultValue(35)]
437                 [Localizable(true)]
438                 public int RowHeaderWidth {
439                         get { return rowheaders_width; }
440                         set {
441                                 if (rowheaders_width != value) {
442                                         rowheaders_width = value;
443                                         OnRowHeaderWidthChanged (EventArgs.Empty);
444                                 }
445                         }
446                 }
447
448                 public Color SelectionBackColor {
449                         get { return selection_backcolor; }
450                         set {
451                                 if (is_default)
452                                         throw new ArgumentException ("Cannot change the value of this property on the default DataGridTableStyle.");
453
454                                 if (selection_backcolor != value) {
455                                         selection_backcolor = value;
456                                         OnSelectionBackColorChanged (EventArgs.Empty);
457                                 }
458                         }
459                 }
460
461                 [Description("The foreground color for the current data grid row")]
462                 public Color SelectionForeColor  {
463                         get { return selection_forecolor; }
464                         set {
465                                 if (is_default)
466                                         throw new ArgumentException ("Cannot change the value of this property on the default DataGridTableStyle.");
467
468                                 if (selection_forecolor != value) {
469                                         selection_forecolor = value;
470                                         OnSelectionForeColorChanged (EventArgs.Empty);
471                                 }
472                         }
473                 }
474
475                 #endregion      // Public Instance Properties
476
477                 #region Private Instance Properties
478                 internal DataGridLineStyle CurrentGridLineStyle {
479                         get {
480                                 if (is_default && datagrid != null) {
481                                         return datagrid.GridLineStyle;
482                                 }
483
484                                 return gridline_style;
485                         }
486                 }
487
488                 internal Color CurrentGridLineColor {
489                         get {
490                                 if (is_default && datagrid != null) {
491                                         return datagrid.GridLineColor;
492                                 }
493
494                                 return gridline_color;
495                         }
496                 }
497
498                 internal Color CurrentHeaderBackColor {
499                         get {
500                                 if (is_default && datagrid != null) {
501                                         return datagrid.HeaderBackColor;
502                                 }
503
504                                 return header_backcolor;
505                         }
506                 }
507
508                 internal Color CurrentHeaderForeColor {
509                         get {
510                                 if (is_default && datagrid != null) {
511                                         return datagrid.HeaderForeColor;
512                                 }
513
514                                 return header_forecolor;
515                         }
516                 }
517
518                 internal int CurrentPreferredColumnWidth {
519                         get {
520                                 if (is_default && datagrid != null) {
521                                         return datagrid.PreferredColumnWidth;
522                                 }
523
524                                 return preferredcolumn_width;
525                         }
526                 }
527
528                 internal int CurrentPreferredRowHeight {
529                         get {
530                                 if (is_default && datagrid != null) {
531                                         return datagrid.PreferredRowHeight;
532                                 }
533
534                                 return preferredrow_height;
535                         }
536                 }
537                 
538                 internal bool CurrentRowHeadersVisible {
539                         get {
540                                 if (is_default && datagrid != null) {
541                                         return datagrid.RowHeadersVisible;
542                                 }
543
544                                 return rowheaders_visible;
545                         }
546                 }
547
548                 internal bool HasRelations {
549                         get { return table_relations.Count > 0; }
550                 }
551
552                 internal string[] Relations {
553                         get {
554                                 string[] rel = new string[table_relations.Count];
555                                 table_relations.CopyTo (rel, 0);
556                                 return rel;
557                         }
558                 }
559
560                 #endregion Private Instance Properties
561
562                 #region Public Instance Methods
563
564                 [MonoTODO]
565                 public bool BeginEdit (DataGridColumnStyle gridColumn,  int rowNumber)
566                 {
567                         throw new NotImplementedException ();
568                 }
569
570                 protected internal virtual DataGridColumnStyle CreateGridColumn (PropertyDescriptor prop)
571                 {
572                         return CreateGridColumn (prop,  false);
573                 }
574
575                 protected internal virtual DataGridColumnStyle CreateGridColumn (PropertyDescriptor prop,  bool isDefault)
576                 {
577                         if (prop.PropertyType == typeof (bool))
578                                 return new DataGridBoolColumn (prop, isDefault);
579                         else {
580                                 // At least to special cases with formats
581                                 if (prop.PropertyType.Equals (typeof (DateTime))) {
582                                         return new DataGridTextBoxColumn (prop, "d", isDefault);
583                                 }
584
585                                 if (prop.PropertyType.Equals (typeof (Int32)) ||
586                                         prop.PropertyType.Equals (typeof (Int16))) {
587                                         return new DataGridTextBoxColumn (prop, "G", isDefault);
588                                 }
589
590                                 return new DataGridTextBoxColumn (prop, isDefault);
591                         }
592                 }
593
594                 protected override void Dispose (bool disposing)
595                 {
596                         base.Dispose (disposing);
597                 }
598
599                 [MonoTODO]
600                 public bool EndEdit ( DataGridColumnStyle gridColumn,  int rowNumber,  bool shouldAbort)
601                 {
602                         throw new NotImplementedException ();
603                 }
604
605                 protected virtual void OnAllowSortingChanged (EventArgs e)
606                 {
607                         if (AllowSortingChanged != null) {
608                                 AllowSortingChanged (this, e);
609                         }
610                 }
611
612                 protected virtual void OnAlternatingBackColorChanged (EventArgs e)
613                 {
614                         if (AlternatingBackColorChanged != null) {
615                                 AlternatingBackColorChanged (this, e);
616                         }
617                 }
618
619                 protected virtual void OnBackColorChanged (EventArgs e)
620                 {
621                         if (BackColorChanged != null) {
622                                 BackColorChanged (this, e);
623                         }
624                 }
625
626                 protected virtual void OnColumnHeadersVisibleChanged (EventArgs e)
627                 {
628                         if (ColumnHeadersVisibleChanged != null) {
629                                 ColumnHeadersVisibleChanged (this, e);
630                         }
631                 }
632
633                 protected virtual void OnForeColorChanged (EventArgs e)
634                 {
635                         if (ForeColorChanged != null) {
636                                 ForeColorChanged (this, e);
637                         }
638                 }
639
640                 protected virtual void OnGridLineColorChanged (EventArgs e)
641                 {
642                         if (GridLineColorChanged != null) {
643                                 GridLineColorChanged (this, e);
644                         }
645                 }
646
647                 protected virtual void OnGridLineStyleChanged (EventArgs e)
648                 {
649                         if (GridLineStyleChanged != null) {
650                                 GridLineStyleChanged (this, e);
651                         }
652                 }
653
654                 protected virtual void OnHeaderBackColorChanged (EventArgs e)
655                 {
656                         if (HeaderBackColorChanged != null) {
657                                 HeaderBackColorChanged (this, e);
658                         }
659                 }
660
661                 protected virtual void OnHeaderFontChanged (EventArgs e)
662                 {
663                         if (HeaderFontChanged != null) {
664                                 HeaderFontChanged (this, e);
665                         }
666                 }
667
668                 protected virtual void OnHeaderForeColorChanged (EventArgs e)
669                 {
670                         if (HeaderForeColorChanged != null) {
671                                 HeaderForeColorChanged (this, e);
672                         }
673                 }
674
675                 protected virtual void OnLinkColorChanged (EventArgs e)
676                 {
677                         if (LinkColorChanged != null) {
678                                 LinkColorChanged (this, e);
679                         }
680                 }
681
682                 protected virtual void OnLinkHoverColorChanged (EventArgs e)
683                 {
684                         if (LinkHoverColorChanged != null) {
685                                 LinkHoverColorChanged (this, e);
686                         }
687                 }
688
689                 protected virtual void OnMappingNameChanged (EventArgs e)
690                 {
691                         if (MappingNameChanged != null) {
692                                 MappingNameChanged(this, e);
693                         }
694                 }
695
696                 protected virtual void OnPreferredColumnWidthChanged (EventArgs e)
697                 {
698                         if (PreferredColumnWidthChanged != null) {
699                                 PreferredColumnWidthChanged (this, e);
700                         }
701                 }
702
703                 protected virtual void OnPreferredRowHeightChanged (EventArgs e)
704                 {
705                         if (PreferredRowHeightChanged != null) {
706                                 PreferredRowHeightChanged (this, e);
707                         }
708                 }
709
710                 protected virtual void OnReadOnlyChanged (EventArgs e)
711                 {
712                         if (ReadOnlyChanged != null) {
713                                 ReadOnlyChanged (this, e);
714                         }
715                 }
716
717                 protected virtual void OnRowHeadersVisibleChanged (EventArgs e)
718                 {
719                         if (RowHeadersVisibleChanged != null) {
720                                 RowHeadersVisibleChanged (this, e);
721                         }
722                 }
723
724                 protected virtual void OnRowHeaderWidthChanged (EventArgs e)
725                 {
726                         if (RowHeaderWidthChanged != null) {
727                                 RowHeaderWidthChanged (this, e);
728                         }
729                 }
730
731                 protected virtual void OnSelectionBackColorChanged (EventArgs e)
732                 {
733                         if (SelectionBackColorChanged != null) {
734                                 SelectionBackColorChanged (this, e);
735                         }
736                 }
737
738                 protected virtual void OnSelectionForeColorChanged (EventArgs e)
739                 {
740                         if (SelectionForeColorChanged != null) {
741                                 SelectionForeColorChanged (this, e);
742                         }
743                 }
744
745                 public void ResetAlternatingBackColor ()
746                 {
747                         AlternatingBackColor = def_alternating_backcolor;
748                 }
749
750                 public void ResetBackColor ()
751                 {
752                         BackColor = def_backcolor;
753                 }
754
755                 public void ResetForeColor ()
756                 {
757                         ForeColor = def_forecolor;
758                 }
759
760                 public void ResetGridLineColor ()
761                 {
762                         GridLineColor = def_gridline_color;
763                 }
764
765                 public void ResetHeaderBackColor ()
766                 {
767                         HeaderBackColor = def_header_backcolor;
768                 }
769
770                 public void ResetHeaderFont ()
771                 {
772                         HeaderFont = def_header_font;
773                 }
774
775                 public void ResetHeaderForeColor ()
776                 {
777                         HeaderForeColor = def_header_forecolor;
778                 }
779
780                 public void ResetLinkColor ()
781                 {
782                         LinkColor = def_link_color;
783                 }
784
785                 public void ResetLinkHoverColor ()
786                 {
787                         LinkHoverColor = def_link_hovercolor;
788                 }
789
790                 public void ResetSelectionBackColor ()
791                 {
792                         SelectionBackColor = def_selection_backcolor;
793                 }
794
795                 public void ResetSelectionForeColor ()
796                 {
797                         SelectionForeColor = def_selection_forecolor;
798                 }
799
800                 protected virtual bool ShouldSerializeAlternatingBackColor ()
801                 {
802                         return (alternating_backcolor != def_alternating_backcolor);
803                 }
804
805                 protected bool ShouldSerializeBackColor ()
806                 {
807                         return (backcolor != def_backcolor);
808                 }
809
810                 protected bool ShouldSerializeForeColor ()
811                 {
812                         return (forecolor != def_forecolor);
813                 }
814
815                 protected virtual bool ShouldSerializeGridLineColor ()
816                 {
817                         return (gridline_color != def_gridline_color);
818                 }
819
820                 protected virtual bool ShouldSerializeHeaderBackColor ()
821                 {
822                         return (header_backcolor != def_header_backcolor);
823                 }
824
825                 protected virtual bool ShouldSerializeHeaderForeColor ()
826                 {
827                         return (header_forecolor != def_header_forecolor);
828                 }
829
830                 protected virtual bool ShouldSerializeLinkColor ()
831                 {
832                         return (link_color != def_link_color);
833                 }
834
835                 protected virtual bool ShouldSerializeLinkHoverColor ()
836                 {
837                         return (link_hovercolor != def_link_hovercolor);
838                 }
839
840                 protected bool ShouldSerializePreferredRowHeight ()
841                 {
842                         return (preferredrow_height != def_preferredrow_height);
843                 }
844
845                 protected bool ShouldSerializeSelectionBackColor ()
846                 {
847                         return (selection_backcolor != def_selection_backcolor);
848                 }
849
850                 protected virtual bool ShouldSerializeSelectionForeColor ()
851                 {
852                         return (selection_forecolor != def_selection_forecolor);
853                 }
854                 #endregion      // Protected Instance Methods
855
856                 #region Private Instance Properties
857                 // Create column styles for this TableStyle
858                 internal void CreateColumnsForTable (bool onlyBind)
859                 {
860                         CurrencyManager mgr = manager;
861                         DataGridColumnStyle st;
862
863                         if (mgr == null) {
864                                 mgr = datagrid.ListManager;
865
866                                 if (mgr == null)
867                                         return;
868                         }
869
870                         for (int i = 0; i < column_styles.Count; i ++)
871                                 column_styles[i].bound = false;
872
873                         table_relations.Clear ();
874                         PropertyDescriptorCollection propcol = mgr.GetItemProperties ();
875
876                         for (int i = 0; i < propcol.Count; i++)
877                         {
878                                 // The column style is already provided by the user
879                                 st = column_styles[propcol[i].Name];
880                                 if (st != null) {
881                                         if (st.Width == -1)
882                                                 st.Width = CurrentPreferredColumnWidth;
883
884                                         st.PropertyDescriptor = propcol[i];
885                                         st.bound = true;
886                                         continue;
887                                 }
888
889                                 if (onlyBind == true) {
890                                         continue;
891                                 }
892
893                                 if (typeof (IBindingList).IsAssignableFrom (propcol[i].PropertyType)) {
894                                         table_relations.Add (propcol[i].Name);
895                                 } else {
896                                         st = CreateGridColumn (propcol[i],  true);
897                                         st.bound = true;
898                                         st.grid = datagrid;
899                                         st.MappingName = propcol[i].Name;
900                                         st.HeaderText = propcol[i].Name;
901                                         st.Width = CurrentPreferredColumnWidth;
902                                         column_styles.Add (st);
903                                 }
904                         }
905
906                 }
907
908                 #endregion Private Instance Properties
909
910                 #region Events
911                 public event EventHandler AllowSortingChanged;
912                 public event EventHandler AlternatingBackColorChanged;
913                 public event EventHandler BackColorChanged;
914                 public event EventHandler ColumnHeadersVisibleChanged;
915                 public event EventHandler ForeColorChanged;
916                 public event EventHandler GridLineColorChanged;
917                 public event EventHandler GridLineStyleChanged;
918                 public event EventHandler HeaderBackColorChanged;
919                 public event EventHandler HeaderFontChanged;
920                 public event EventHandler HeaderForeColorChanged;
921                 public event EventHandler LinkColorChanged;
922                 public event EventHandler LinkHoverColorChanged;
923                 public event EventHandler MappingNameChanged;
924                 public event EventHandler PreferredColumnWidthChanged;
925                 public event EventHandler PreferredRowHeightChanged;
926                 public event EventHandler ReadOnlyChanged;
927                 public event EventHandler RowHeadersVisibleChanged;
928                 public event EventHandler RowHeaderWidthChanged;
929                 public event EventHandler SelectionBackColorChanged;
930                 public event EventHandler SelectionForeColorChanged;
931                 #endregion      // Events
932         }
933 }
934