public void PrintToGrid() { for (int i = 0; i < dt.Columns.Count; i++) { // DataTable dt=(DataTable) dataGridView1.DataSource; if (templAdress.ContainsKey(new Point(0, i))) { TemplateRange tmp = templAdress[new Point(0, i)]; int l = 1; if (dataGridView2.DataSource != null) { for (int j = tmp.FirstCell.X; j < tmp.EndCell.X; j++, l++) { try { dt.Rows[l][i] = dataGridView2.Rows[j].Cells[tmp.EndCell.Y].Value; } // dataGridView1.Rows[l].Cells[i].Value = dataGridView2.Rows[j].Cells[tmp.EndCell.Y].Value; } catch (Exception) { DataRow dr = dt.NewRow(); dt.Rows.Add(dr); dt.Rows[l][i] = dataGridView2.Rows[j].Cells[tmp.EndCell.Y].Value; // dataGridView1.Rows[l].Cells[i].Value = dataGridView2.Rows[j].Cells[tmp.EndCell.Y].Value; } } } else { try { dt.Rows[l][i] = tmp.FirstCellString() + ":" + tmp.EndCellString(); } // dataGridView1.Rows[l].Cells[i].Value = dataGridView2.Rows[j].Cells[tmp.EndCell.Y].Value; } catch (Exception) { DataRow dr = dt.NewRow(); dt.Rows.Add(dr); dt.Rows[l][i] = tmp.FirstCellString() + ":" + tmp.EndCellString(); // dataGridView1.Rows[l].Cells[i].Value = dataGridView2.Rows[j].Cells[tmp.EndCell.Y].Value; } break; } } } dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None; dataGridView1.ColumnHeadersVisible = false; dataGridView1.DataSource = dt; dataGridView1.ColumnHeadersVisible = true; dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; //dataGridView1.Invoke((Action)(() => dataGridView1.DataSource = dt)); // dataGridView1.Invalidate(); }
public DicXML(DataGridViewCell Cell, TemplateRange Range) { this.Cell = Cell; this.Range = Range; }