Пример #1
0
        private void CopyDataGridView(DataGridView dgv_org)
        {
            try
            {
                if (DgvDetails.Columns.Count == 0)
                {
                    foreach (DataGridViewColumn dgvc in dgv_org.Columns)
                    {
                        DgvDetails.Columns.Add(dgvc.Clone() as DataGridViewColumn);
                    }
                }
                DataGridViewButtonColumn NewCol = new DataGridViewButtonColumn();

                DgvDetails.Columns.Add(NewCol);
                NewCol.Text       = "Add to Track list";
                NewCol.Name       = "BtnColAdd";
                NewCol.HeaderText = "Add To List";
                NewCol.Width      = 150;
                NewCol.UseColumnTextForButtonValue = true;
                DataGridViewRow row = new DataGridViewRow();

                for (int i = 0; i < dgv_org.Rows.Count; i++)
                {
                    row = (DataGridViewRow)dgv_org.Rows[i].Clone();
                    int intColIndex = 0;
                    foreach (DataGridViewCell cell in dgv_org.Rows[i].Cells)
                    {
                        row.Cells[intColIndex].Value = cell.Value;
                        intColIndex++;
                    }
                    DgvDetails.Rows.Add(row);
                    if (ClsDataBase.CheckTrackScript(row.Cells[StrScriptIdCol].Value.ToString()))
                    {
                        row.DefaultCellStyle.BackColor = Color.Green;
                    }
                }
                DgvDetails.AllowUserToAddRows = false;
                DgvDetails.Refresh();
            }
            catch (Exception ex)
            {
                ClsLog.WriteLog("Copy DataGridViw" + ex.Message);
            }
        }