GridControlColumn.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. using System.Windows.Forms;
  2. using System.ComponentModel;
  3. using System.Drawing.Design;
  4. using FastReport.Utils;
  5. using FastReport.TypeEditors;
  6. using FastReport.Data;
  7. namespace FastReport.Dialog
  8. {
  9. /// <summary>
  10. /// Represents the <see cref="GridControl"/>'s column.
  11. /// Wraps the <see cref="System.Windows.Forms.DataGridViewTextBoxColumn"/> class.
  12. /// </summary>
  13. public class GridControlColumn : Base
  14. {
  15. private DataGridViewTextBoxColumn column;
  16. private string dataColumn;
  17. #region Properties
  18. /// <summary>
  19. /// Gets or sets the mode by which the column automatically adjusts its width.
  20. /// Wraps the <see cref="System.Windows.Forms.DataGridViewColumn.AutoSizeMode"/> property.
  21. /// </summary>
  22. [DefaultValue(DataGridViewAutoSizeColumnMode.NotSet)]
  23. [Category("Behavior")]
  24. public DataGridViewAutoSizeColumnMode AutoSizeMode
  25. {
  26. get { return column.AutoSizeMode; }
  27. set { column.AutoSizeMode = value; }
  28. }
  29. /// <summary>
  30. /// Gets or sets the data column attached to this column.
  31. /// </summary>
  32. [Category("Data")]
  33. [Editor("FastReport.TypeEditors.DataColumnEditor, FastReport", typeof(UITypeEditor))]
  34. public string DataColumn
  35. {
  36. get { return dataColumn; }
  37. set { dataColumn = value; }
  38. }
  39. /// <summary>
  40. /// Gets or sets the caption text on the column's header cell.
  41. /// Wraps the <see cref="System.Windows.Forms.DataGridViewColumn.HeaderText"/> property.
  42. /// </summary>
  43. [Category("Appearance")]
  44. public string HeaderText
  45. {
  46. get { return column.HeaderText; }
  47. set { column.HeaderText = value; }
  48. }
  49. /// <summary>
  50. /// Gets or sets the column's default cell style.
  51. /// Wraps the <see cref="System.Windows.Forms.DataGridViewColumn.DefaultCellStyle"/> property.
  52. /// </summary>
  53. [Category("Appearance")]
  54. public DataGridViewCellStyle DefaultCellStyle
  55. {
  56. get { return column.DefaultCellStyle; }
  57. set { column.DefaultCellStyle = value; }
  58. }
  59. /// <summary>
  60. /// Gets or sets a value that represents the width of the column when it is in fill mode relative to the widths of other fill-mode columns in the control.
  61. /// Wraps the <see cref="System.Windows.Forms.DataGridViewColumn.FillWeight"/> property.
  62. /// </summary>
  63. [DefaultValue(100f)]
  64. [Category("Layout")]
  65. public float FillWeight
  66. {
  67. get { return column.FillWeight; }
  68. set { column.FillWeight = value; }
  69. }
  70. /// <summary>
  71. /// Gets or sets the current width of the column.
  72. /// Wraps the <see cref="System.Windows.Forms.DataGridViewColumn.Width"/> property.
  73. /// </summary>
  74. [DefaultValue(100)]
  75. [Category("Layout")]
  76. public int Width
  77. {
  78. get { return column.Width; }
  79. set { column.Width = value; }
  80. }
  81. /// <summary>
  82. /// Gets or sets a value indicating whether the column is visible.
  83. /// Wraps the <see cref="System.Windows.Forms.DataGridViewColumn.Visible"/> property.
  84. /// </summary>
  85. [DefaultValue(true)]
  86. [Category("Behavior")]
  87. public bool Visible
  88. {
  89. get { return column.Visible; }
  90. set { column.Visible = value; }
  91. }
  92. /// <summary>
  93. /// This property is not relevant to this class.
  94. /// </summary>
  95. [Browsable(false)]
  96. public new string Name
  97. {
  98. get { return base.Name; }
  99. set { base.Name = value; }
  100. }
  101. /// <summary>
  102. /// This property is not relevant to this class.
  103. /// </summary>
  104. [Browsable(false)]
  105. public new Restrictions Restrictions
  106. {
  107. get { return base.Restrictions; }
  108. set { base.Restrictions = value; }
  109. }
  110. internal DataGridViewTextBoxColumn Column
  111. {
  112. get { return column; }
  113. }
  114. #endregion
  115. #region Public Methods
  116. /// <inheritdoc/>
  117. public override void Assign(Base source)
  118. {
  119. BaseAssign(source);
  120. }
  121. /// <inheritdoc/>
  122. public override void Serialize(FRWriter writer)
  123. {
  124. GridControlColumn c = writer.DiffObject as GridControlColumn;
  125. writer.ItemName = "Column";
  126. if (AutoSizeMode != c.AutoSizeMode)
  127. writer.WriteValue("AutoSizeMode", AutoSizeMode);
  128. if (DataColumn != c.DataColumn)
  129. writer.WriteStr("DataColumn", DataColumn);
  130. if (HeaderText != c.HeaderText)
  131. writer.WriteStr("HeaderText", HeaderText);
  132. GridControl.WriteCellStyle(writer, "DefaultCellStyle", DefaultCellStyle, c.DefaultCellStyle);
  133. if (FillWeight != c.FillWeight)
  134. writer.WriteFloat("FillWeight", FillWeight);
  135. if (Width != c.Width)
  136. writer.WriteInt("Width", Width);
  137. if (Visible != c.Visible)
  138. writer.WriteBool("Visible", Visible);
  139. }
  140. internal void InitColumn()
  141. {
  142. if (Report != null)
  143. {
  144. FastReport.Data.Column column = DataHelper.GetColumn(Report.Dictionary, DataColumn);
  145. if (column != null)
  146. this.column.DataPropertyName = column.Name;
  147. }
  148. }
  149. #endregion
  150. /// <summary>
  151. /// Initializes a new instance of the <b>GridControlColumn</b> class with default settings.
  152. /// </summary>
  153. public GridControlColumn()
  154. {
  155. column = new DataGridViewTextBoxColumn();
  156. }
  157. }
  158. }