public void _0001_AddRows() { var table = new ExportTable(); table.Columns.Add(new ExportColumnItem() { Name = "columnIndex" }); table.Columns.Add(new ExportColumnItem() { Name = "columnFirstName" }); table.Columns.Add(new ExportColumnItem() { Name = "columnLastName" }); for (int i = 0; i < 5; i++) { var row = new ExportRowItem(); table.Rows.Add(row); row.Cells[0].Value = "Index:" + i.ToString(); row.Cells[1].Value = "Homer"; row.Cells[2].Value = "Simpson"; } foreach (var item in table.Rows) { Debug.WriteLine(item); } Assert.AreEqual(3, table.Columns.Count); Assert.AreEqual(5, table.Rows.Count); }
public void _0003_DataGrid_To_ExportTable() { var dgv = TestDataGridView(); var table = new ExportTable(); foreach (DataGridViewColumn dgvColumn in dgv.Columns) { var exportColumn = new ExportColumnItem() { Name = dgv.Name, HeaderText = dgvColumn.HeaderText, DisplayIndex = dgvColumn.DisplayIndex, Visible = dgvColumn.Visible, }; table.Columns.Add(exportColumn); } foreach (DataGridViewRow dgvRow in dgv.Rows) { var newRow = new ExportRowItem(); table.Rows.Add(newRow); for (var i = 0; i < dgvRow.Cells.Count; i++) { newRow.Cells[i].Value = dgvRow.Cells[i].Value.ToString(); } } foreach (var item in table.Rows) { Debug.WriteLine(item); } Assert.AreEqual(3, table.Columns.Count); Assert.AreEqual(4, table.Rows.Count); }