private void btnChoose_Click(object sender, EventArgs e) { try { if (rdrYesUse.Checked == true) { CopyGridView copyGrid = new CopyGridView(); copyGrid.copyDataGridViewNotDelete(dgvAddOutDevice, dgvListDevice); dgvListDevice.Columns.Add("Ma_TS_Repair", "Vật tư cần sửa chữa"); foreach (DataGridViewRow row in dgvRepairDevice.Rows) { Boolean CheckRow = Convert.ToBoolean(row.Cells["Select"].Value); if (CheckRow) { string MTS = row.Cells["Ma_TS"].Value.ToString(); foreach (DataGridViewRow row2 in dgvListDevice.Rows) { row2.Cells["Ma_TS_Repair"].Value = MTS; } } } AntiDuplicated antiDuplicated = new AntiDuplicated(); antiDuplicated.AntiColumnDuplicate(dgvListDevice); string ColumnName = dgvAddOutDevice.Columns["Select"].Name.ToString(); AutoComplete.AutoUnselectAll(dgvAddOutDevice, ColumnName); foreach (DataGridViewRow row in dgvRepairDevice.Rows) { Boolean CheckRow = Convert.ToBoolean(row.Cells["Select"].Value); if (CheckRow) { int n = row.Index; dgvRepairDevice.Rows.RemoveAt(n); } } btnFinalTransfer_Click(this, new EventArgs()); } else if (rdrNoUse.Checked == true) { CopyGridView copyGrid = new CopyGridView(); copyGrid.CopyDataGridView(dgvRepairDevice, dgvListDevice); foreach (DataGridViewRow row in dgvRepairDevice.Rows) { Boolean CheckRow = Convert.ToBoolean(row.Cells["Select"].Value); if (CheckRow) { int n = row.Index; dgvRepairDevice.Rows.RemoveAt(n); } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnTransfer_Click(object sender, EventArgs e) { try { if (dataGridView2.Columns.Count == 0) { //duyet tat ca cac cot cua bang 1 foreach (DataGridViewColumn dgvc in dataGridView1.Columns) { //chuyen cac cot cua bang 1 ve dang clone (khong so huu) sau do add vao bang 2 dataGridView2.Columns.Add(dgvc.Clone() as DataGridViewColumn); } } //tao doi tuong row trong datagridviewrow DataGridViewRow row = new DataGridViewRow(); //xet hang duoc chon trong bang 1 for (int i = 0; i < dataGridView1.Rows.Count; i++) { //doi tuong row duoc gan voi row trong bang 1 duoc chon va dua ve dang clone row = (DataGridViewRow)dataGridView1.Rows[i].Clone(); int intColIndex = 0; //khai bao value so column/cell //xet tat ca cell trong row duoc chon cua bang 1 foreach (DataGridViewCell cell in dataGridView1.Rows[i].Cells) { //gan gia tri tung cell cua doi tuong row bang gia tri cua cac cell trong 1 dong của bang 1 row.Cells[intColIndex].Value = cell.Value; intColIndex++; } if (Convert.ToBoolean(dataGridView1.Rows[i].Cells["Select"].Value) == true) { dataGridView2.Rows.Add(row); //add cac row da duoc check vao bang 2 int n = dataGridView1.Rows[i].Index; //lay so dong cua row vua duoc move sang bang 2 dataGridView1.Rows.RemoveAt(n); //xoa row do khỏ datagridview } } dataGridView2.AllowUserToAddRows = true; dataGridView2.Refresh(); for (int j = 0; j < dataGridView2.Rows.Count; j++) { int Check = Convert.ToInt32(dataGridView2.Rows[j].Cells["Ma_TS"].Value); for (int k = j + 1; k < dataGridView2.Rows.Count; k++) { int Check2 = Convert.ToInt32(dataGridView2.Rows[k].Cells["Ma_TS"].Value); if (Check == Check2) { dataGridView2.Rows.Add(); int n2 = dataGridView2.Rows[k].Index; dataGridView2.Rows.RemoveAt(n2); } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } DataGridViewTextBoxColumn column = new DataGridViewTextBoxColumn(); column.Name = "Remark"; column.HeaderText = "Remark"; column.Visible = true; dataGridView2.Columns.Add(column); AntiDuplicated.AntiColumnDuplicate(dataGridView2); }