/// <summary> /// Initializes a new instance of the <see cref="FormDetail" /> class. /// </summary> /// <param name="dataTable">The data table.</param> /// <param name="uniqueFieldName">Name of the unique field.</param> /// <param name="setting">a FileSetting</param> /// <param name="readOnly">if set to <c>true</c> the data will not be editable</param> /// <param name="onlyErrors">if set to <c>true</c> non error will be hidden</param> /// <param name="frozenColumns">The frozen columns.</param> /// <param name="cancellationToken">The cancellation token</param> /// public FormDetail(DataTable dataTable, IEnumerable <string> uniqueFieldName, IFileSetting setting, bool readOnly, bool onlyErrors, int frozenColumns, CancellationToken cancellationToken = default(CancellationToken)) { Contract.Requires(dataTable != null); SuspendLayout(); DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle { BackColor = System.Drawing.Color.Gainsboro }; DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle { Alignment = DataGridViewContentAlignment.MiddleLeft, BackColor = System.Drawing.SystemColors.Window, Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))), ForeColor = System.Drawing.Color.Black, SelectionBackColor = System.Drawing.SystemColors.Highlight, SelectionForeColor = System.Drawing.SystemColors.HighlightText, WrapMode = System.Windows.Forms.DataGridViewTriState.False }; detailControl = new DetailControl { CancellationToken = cancellationToken, AlternatingRowDefaultCellSyle = dataGridViewCellStyle1, DefaultCellStyle = dataGridViewCellStyle2, Dock = DockStyle.Fill, Location = new System.Drawing.Point(0, 0), Name = "detailControl", ReadOnly = readOnly, Size = new System.Drawing.Size(767, 394), TabIndex = 0, FileSetting = setting }; AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); ClientSize = new System.Drawing.Size(767, 394); MinimumSize = new System.Drawing.Size(100, 100); Controls.Add(this.detailControl); Icon = global::CsvToolLib.Resources.SubFormIcon; KeyPreview = true; Name = "FormDetail"; ResumeLayout(false); detailControl.DataTable = dataTable; // Need to set UniqueFieldName last detailControl.UniqueFieldName = uniqueFieldName; if (frozenColumns > 0) { detailControl.FrozenColumns = frozenColumns; } if (onlyErrors) { detailControl.OnlyShowErrors(); } }
public void DetailControlTest() { using (var dt = new DataTable()) { dt.Columns.Add(new DataColumn { ColumnName = "ID", DataType = typeof(int) }); dt.Columns.Add(new DataColumn { ColumnName = "Text", DataType = typeof(string) }); dt.Columns.Add(new DataColumn { ColumnName = "Date", DataType = typeof(DateTime) }); dt.Columns.Add(new DataColumn { ColumnName = "Bool", DataType = typeof(bool) }); for (var line = 1; line < 5000; line++) { var row = dt.NewRow(); row[0] = line; row[1] = $"This is text {line / 2}"; row[2] = new DateTime(2001, 6, 6).AddHours(line * 3); row[3] = line % 3 == 0; if (SecureString.Random.Next(1, 10) == 5) { row.SetColumnError(SecureString.Random.Next(0, 3), "Error"); } if (SecureString.Random.Next(1, 50) == 5) { row.RowError = "Row Error"; } dt.Rows.Add(row); } using (var dc = new DetailControl()) { dc.Show(); dc.DataTable = dt; dc.OnlyShowErrors(); dc.MoveMenu(); } } }