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