private void moveDown() { if (DGV.RowCount > 0) { if (DGV.SelectedRows.Count > 0) { int rowCount = DGV.Rows.Count; int index = DGV.SelectedCells[0].OwningRow.Index; if (index == (rowCount - 2)) // include the header row { return; } DataGridViewRowCollection rows = DGV.Rows; // remove the next row and add it in front of the selected row. DataGridViewRow row = rows[index]; DataGridViewRow prevRow = rows[index + 1]; String rowDate = row.Cells[5].Value.ToString(); String prevRowDate = prevRow.Cells[5].Value.ToString(); row.Cells[5].Value = prevRowDate; prevRow.Cells[5].Value = rowDate; DataGridViewRow nextRow = rows[index + 1]; rows.Remove(nextRow); nextRow.Frozen = false; rows.Insert(index, nextRow); DGV.ClearSelection(); DGV.Rows[index + 1].Selected = true; } else if (DGV.SelectedCells.Count == 1 && DGV.CurrentCell.RowIndex != DGV.Rows.Count - 2) { DGV.CurrentCell = DGV.Rows[DGV.CurrentCell.RowIndex + 1].Cells[DGV.CurrentCell.ColumnIndex]; } } }
private void moveSelectedRowsDown() { int numSelectedRows = dataGridView2.Rows.GetRowCount(DataGridViewElementStates.Selected); int numRows = dataGridView2.Rows.Count; DataGridViewRowCollection rows = dataGridView2.Rows; List <int> selected = new List <int>(); if (numRows > 1) { numRows -= 1; // don't include the 'add new test'-row and don't move beyond the last row for (int s = 0; s < numSelectedRows; s++) { selected.Add(dataGridView2.SelectedRows[s].Index); } selected.Sort(); selected.Reverse(); // Get values in decreasing order foreach (int rowIndex in selected) { if (rowIndex >= 0 && rowIndex < (numRows - 1)) { DataGridViewRow rowBelowSelected = rows[rowIndex + 1]; rowBelowSelected.Selected = false; rows.Remove(rowBelowSelected); rows.Insert(rowIndex, rowBelowSelected); rows[rowIndex + 1].Selected = true; } else { break; } } } }
private void btnUpAsset_Click(object sender, EventArgs e) { if (tablaAssets.RowCount > 0) { if (tablaAssets.SelectedRows.Count > 0) { int rowCount = tablaAssets.Rows.Count; int index = tablaAssets.SelectedCells[0].OwningRow.Index; if (index == 0) { return; } DataGridViewRowCollection rows = tablaAssets.Rows; // remove the previous row and add it behind the selected row. DataGridViewRow prevRow = rows[index - 1]; rows.Remove(prevRow); prevRow.Frozen = false; rows.Insert(index, prevRow); tablaAssets.ClearSelection(); tablaAssets.Rows[index - 1].Selected = true; } } }
private void btnRelMovUp_Click(object sender, EventArgs e) { if (dgvRelEnt.RowCount > 0) { if (dgvRelEnt.SelectedRows.Count > 0) { int rowCount = dgvRelEnt.Rows.Count; int index = dgvRelEnt.SelectedCells[0].OwningRow.Index; if (index == 0) { return; } DataGridViewRowCollection rows = dgvRelEnt.Rows; // remove the previous row and add it behind the selected row. DataGridViewRow prevRow = rows[index - 1]; rows.Remove(prevRow); prevRow.Frozen = false; rows.Insert(index, prevRow); dgvRelEnt.ClearSelection(); dgvRelEnt.Rows[index - 1].Selected = true; UpdateRelativeBars(); } } }
private void moveUp() { if (DGV.RowCount > 0) { if (DGV.SelectedRows.Count > 0) { int rowCount = DGV.Rows.Count; int index = DGV.SelectedCells[0].OwningRow.Index; if (index == 0) { return; } DataGridViewRowCollection rows = DGV.Rows; // remove the previous row and add it behind the selected row. DataGridViewRow row = rows[index]; DataGridViewRow prevRow = rows[index - 1]; String rowDate = row.Cells[5].Value.ToString(); String prevRowDate = prevRow.Cells[5].Value.ToString(); row.Cells[5].Value = prevRowDate; prevRow.Cells[5].Value = rowDate; rows.Remove(prevRow); prevRow.Frozen = false; rows.Insert(index, prevRow); DGV.ClearSelection(); DGV.Rows[index - 1].Selected = true; } else if (DGV.SelectedCells.Count == 1 && DGV.CurrentCell.RowIndex != 0) { DGV.CurrentCell = DGV.Rows[DGV.CurrentCell.RowIndex - 1].Cells[DGV.CurrentCell.ColumnIndex]; } } }
private void btnRelMovDwn_Click(object sender, EventArgs e) { if (dgvRelEnt.RowCount > 0) { if (dgvRelEnt.SelectedRows.Count > 0) { int rowCount = dgvRelEnt.Rows.Count; int index = dgvRelEnt.SelectedCells[0].OwningRow.Index; if (index == (rowCount - 1)) { return; } DataGridViewRowCollection rows = dgvRelEnt.Rows; // remove the next row and add it in front of the selected row. DataGridViewRow nextRow = rows[index + 1]; rows.Remove(nextRow); nextRow.Frozen = false; rows.Insert(index, nextRow); dgvRelEnt.ClearSelection(); dgvRelEnt.Rows[index + 1].Selected = true; UpdateRelativeBars(); } } }
private void moveDown() { if (dgvDepo.RowCount > 0) { if (dgvDepo.SelectedRows.Count > 0) { int rowCount = dgvDepo.Rows.Count; int index = dgvDepo.SelectedCells[0].OwningRow.Index; if (index == (rowCount - 2)) // include the header row { return; } DataGridViewRowCollection rows = dgvDepo.Rows; // remove the next row and add it in front of the selected row. DataGridViewRow nextRow = rows[index + 1]; rows.Remove(nextRow); nextRow.Frozen = false; rows.Insert(index, nextRow); dgvDepo.ClearSelection(); dgvDepo.Rows[index + 1].Selected = true; } } }
private void btnsinglecancel_Click(object sender, EventArgs e) { if (txtSOD.Text == cboStudent.Text) { btnsinglecancel.Enabled = true; SqlConnection con = new SqlConnection(scsb.ToString()); con.Open(); string strSQL = $@"delete from OrderDetail where OD_Name = '{ dataGridView2.CurrentRow.Cells[2].Value}' and OD_Meals = '{dataGridView2.CurrentRow.Cells[3].Value}' and OD_Date = '{dataGridView2.CurrentRow.Cells[8].Value}'"; SqlCommand cmd = new SqlCommand(strSQL, con); cmd.ExecuteNonQuery(); con.Close(); DataGridViewRowCollection rows2 = dataGridView2.Rows; rows2.Remove(dataGridView2.CurrentRow); int sum = 0; int a = 0; for (int i = 0; i < dataGridView2.RowCount - 1; i++) { Int32.TryParse(dataGridView2.Rows[i].Cells[6].Value.ToString(), out a); sum += a; } txtamount.Text = sum.ToString(); } }
private void moveUp() { if (dgvDepo.RowCount > 0) { if (dgvDepo.SelectedRows.Count > 0) { int rowCount = dgvDepo.Rows.Count; int index = dgvDepo.SelectedCells[0].OwningRow.Index; if (index == 0) { return; } DataGridViewRowCollection rows = dgvDepo.Rows; // remove the previous row and add it behind the selected row. DataGridViewRow prevRow = rows[index - 1]; rows.Remove(prevRow); prevRow.Frozen = false; rows.Insert(index, prevRow); dgvDepo.ClearSelection(); dgvDepo.Rows[index - 1].Selected = true; } } }
private void moveSelectedRowsUp() { //uses the index of the selected rows and reorder them to be able to move several rows at once int numSelectedRows = dataGridView2.Rows.GetRowCount(DataGridViewElementStates.Selected); int numRows = dataGridView2.Rows.Count; DataGridViewRowCollection rows = dataGridView2.Rows; // all the rows in dataGridviw List <int> selected = new List <int>(); // index of all the selected rows if (numRows > 1) // if the gridView contains at least one row (other than the 'add new test'-row) { numRows -= 1; // don't include the 'add new test'-row for (int s = 0; s < numSelectedRows; s++) // get all the index of all the selected rows into a list { selected.Add(dataGridView2.SelectedRows[s].Index); // get index in dataGridView for each of the selected rows } selected.Sort(); // increasing order foreach (int rowIndex in selected) { if (rowIndex > 0 && rowIndex < numRows) { DataGridViewRow rowAboveSelected = rows[rowIndex - 1]; rowAboveSelected.Selected = false; rows.Remove(rowAboveSelected); rows.Insert(rowIndex, rowAboveSelected); rows[rowIndex - 1].Selected = true; } else { break; } } } }
private void btnDwnAsset_Click(object sender, EventArgs e) { if (tablaAssets.RowCount > 0) { if (tablaAssets.SelectedRows.Count > 0) { int rowCount = tablaAssets.Rows.Count; int index = tablaAssets.SelectedCells[0].OwningRow.Index; if (index == (rowCount - 1)) // include the header row { return; } DataGridViewRowCollection rows = tablaAssets.Rows; // remove the next row and add it in front of the selected row. DataGridViewRow nextRow = rows[index + 1]; rows.Remove(nextRow); nextRow.Frozen = false; rows.Insert(index, nextRow); tablaAssets.ClearSelection(); tablaAssets.Rows[index + 1].Selected = true; } } }
private void btnDeleteRow_Click(object sender, EventArgs e) { DataGridViewRowCollection rows = this.dataGridView.Rows; number--; if (number >= 0) { rows.Remove(this.dataGridView.Rows[number]); } }
public IList <DataGridViewRow> RemoveRows(IList <DataGridViewRow> rows) { DataGridViewRowCollection col = this.view.Rows; foreach (DataGridViewRow row in rows) { col.Remove(row); SchemaItem item = row.Tag as SchemaItem; if (item != null) { this.items.Remove(item); } } return(rows); }
public static void dgvRowMoveUpDown(DataGridView dgv, bool moveDown) { if (dgv.SelectedRows.Count > 0) { int rowCount = dgv.Rows.Count; int index = dgv.SelectedCells[0].OwningRow.Index; if (moveDown) { if (index == (rowCount - 1)) { return; } } else { if (index == 0) { return; } } DataGridViewRowCollection rows = dgv.Rows; DataGridViewRow tempRow; if (moveDown) { tempRow = rows[index + 1]; } else { tempRow = rows[index - 1]; } rows.Remove(tempRow); tempRow.Frozen = false; rows.Insert(index, tempRow); dgv.ClearSelection(); if (moveDown) { dgv.Rows[index + 1].Selected = true; } else { dgv.Rows[index - 1].Selected = true; } } }
public static void RemoveAll(this DataGridViewRowCollection collection, DataGridViewSelectedRowCollection rowCollection) { if (collection == null) { throw new ArgumentNullException(nameof(collection)); } if (rowCollection == null) { throw new ArgumentNullException(nameof(rowCollection)); } foreach (DataGridViewRow row in rowCollection) { collection.Remove(row); } }
public static void RemoveAll(this DataGridViewRowCollection collection, IEnumerable <DataGridViewRow> rows) { if (collection == null) { throw new ArgumentNullException(nameof(collection)); } if (rows == null) { throw new ArgumentNullException(nameof(rows)); } foreach (var row in rows) { collection.Remove(row); } }
internal static void MoveUp(this DataGridView dgv) { int index = dgv.SelectedRows[0].Index; if (index == 0) { return; } DataGridViewRowCollection rows = dgv.Rows; DataGridViewRow prevRow = rows[index - 1]; rows.Remove(prevRow); prevRow.Frozen = false; rows.Insert(index, prevRow); dgv.ClearSelection(); dgv.Rows[index - 1].Selected = true; }
internal static void MoveDown(this DataGridView dgv) { int rowCount = dgv.Rows.Count; int index = dgv.SelectedRows[0].Index; if (index == rowCount - 1) { return; } DataGridViewRowCollection rows = dgv.Rows; DataGridViewRow nextRow = rows[index + 1]; rows.Remove(nextRow); nextRow.Frozen = false; rows.Insert(index, nextRow); dgv.ClearSelection(); dgv.Rows[index + 1].Selected = true; }
public static void DataGridViewMoveDown(DataGridView dgv, DataGridViewRow row) { if (row == null) { return; } if (dgv.Rows.Count > 0 && row.Index > 0) { DataGridViewRowCollection rows = dgv.Rows; // remove the previous row and add it behind the selected row. DataGridViewRow prevRow = rows[row.Index + 1]; rows.Remove(prevRow); prevRow.Frozen = false; rows.Insert(row.Index, prevRow); dgv.ClearSelection(); dgv.Rows[row.Index + 1].Selected = true; } }
private void desce() { try { int totalRows = dataGridView1.Rows.Count; int idx = dataGridView1.SelectedCells[0].OwningRow.Index; if (idx == totalRows - 2) { return; } int col = dataGridView1.SelectedCells[0].OwningColumn.Index; DataGridViewRowCollection rows = dataGridView1.Rows; DataGridViewRow row = rows[idx]; rows.Remove(row); rows.Insert(idx + 1, row); dataGridView1.ClearSelection(); dataGridView1.Rows[idx + 1].Cells[col].Selected = true; } catch { } }
/// <summary> /// Move row down for a selected row /// </summary> /// <param name="pDataGridView"></param> public static void MoveRowDown(this DataGridView pDataGridView) { if (pDataGridView.RowCount > 0) { if (pDataGridView.SelectedRows.Count > 0) { int rowCount = pDataGridView.Rows.Count; int selectedIndex = pDataGridView.SelectedCells[0].OwningRow.Index; DataGridViewRowCollection rows = pDataGridView.Rows; // remove the next row and add it in front of the selected row. DataGridViewRow nextRow = rows[selectedIndex + 1]; rows.Remove(nextRow); nextRow.Frozen = false; rows.Insert(selectedIndex, nextRow); pDataGridView.ClearSelection(); pDataGridView.Rows[selectedIndex + 1].Selected = true; } } }
private void btn_Ordertype_Up_Click(object sender, EventArgs e) { if (Grid_Order_Type_Abs.Rows.Count > 0) { int rowscount = Grid_Order_Type_Abs.Rows.Count; int index = Grid_Order_Type_Abs.SelectedCells[0].OwningRow.Index; if (index == 0) { return; } DataGridViewRowCollection rows = Grid_Order_Type_Abs.Rows; // remove the previous row and add it behind the selected row. DataGridViewRow prevRow = rows[index - 1];; rows.Remove(prevRow); prevRow.Frozen = false; rows.Insert(index, prevRow); Grid_Order_Type_Abs.ClearSelection(); Grid_Order_Type_Abs.Rows[index - 1].Selected = true; Grid_Order_Type_Abs.FirstDisplayedScrollingRowIndex = Grid_Order_Type_Abs.SelectedRows[0].Index; } }
private void btnDown_Click(object sender, EventArgs e) { DataGridView grid = DG; try { int totalRows = grid.Rows.Count; int idx = grid.SelectedCells[0].OwningRow.Index; if (idx == totalRows - 1) { return; } int col = grid.SelectedCells[0].OwningColumn.Index; DataGridViewRowCollection rows = grid.Rows; DataGridViewRow row = rows[idx]; rows.Remove(row); rows.Insert(idx + 1, row); grid.ClearSelection(); grid.Rows[idx + 1].Cells[col].Selected = true; } catch { } }
private void moveDown() { if (Grid_Comments.RowCount > 0) { //if (Grid_Comments.SelectedRows.Count > 0) //{ int rowCount = Grid_Comments.Rows.Count; int index = Grid_Comments.SelectedCells[0].OwningRow.Index; if (index == (rowCount - 2)) // include the header row { return; } DataGridViewRowCollection rows = Grid_Comments.Rows; // remove the next row and add it in front of the selected row. DataGridViewRow nextRow = rows[index + 1]; rows.Remove(nextRow); nextRow.Frozen = false; rows.Insert(index, nextRow); Grid_Comments.ClearSelection(); Grid_Comments.Rows[index + 1].Selected = true; for (int i = 0; i < Grid_Comments.Rows.Count; i++) { Hashtable hsforSP = new Hashtable(); DataTable dt = new System.Data.DataTable(); hsforSP.Add("@Trans", "UPDATE_ORDER"); hsforSP.Add("@Task_Confirm_Id", Grid_Comments.Rows[i].Cells[4].Value); hsforSP.Add("@Assigned_Order", i); dt = dataaccess.ExecuteSP("Sp_Task_Confirmation_Master", hsforSP); } //} } }
private void btn_Order_Type_Down_Click(object sender, EventArgs e) { if (Grid_Order_Type_Abs.Rows.Count > 0) { int rowCount = Grid_Order_Type_Abs.Rows.Count; int index = Grid_Order_Type_Abs.SelectedCells[0].OwningRow.Index; if (index == (rowCount - 1)) // include the header row { return; } DataGridViewRowCollection rows = Grid_Order_Type_Abs.Rows; // remove the next row and add it in front of the selected row. DataGridViewRow nextRow = rows[index + 1]; rows.Remove(nextRow); nextRow.Frozen = false; rows.Insert(index, nextRow); Grid_Order_Type_Abs.ClearSelection(); Grid_Order_Type_Abs.Rows[index + 1].Selected = true; Grid_Order_Type_Abs.FirstDisplayedScrollingRowIndex = Grid_Order_Type_Abs.SelectedRows[0].Index; } }
/// <summary> /// Move row up for a selected row /// </summary> /// <param name="pDataGridView"></param> public static void MoveRowUp(this DataGridView pDataGridView) { if (pDataGridView.RowCount > 0) { if (pDataGridView.SelectedRows.Count > 0) { int selectedIndex = pDataGridView.SelectedCells[0].OwningRow.Index; if (selectedIndex == 0) { return; } DataGridViewRowCollection rows = pDataGridView.Rows; // remove the previous row and add it behind the selected row. DataGridViewRow prevRow = rows[selectedIndex - 1]; rows.Remove(prevRow); prevRow.Frozen = false; rows.Insert(selectedIndex, prevRow); pDataGridView.ClearSelection(); pDataGridView.Rows[selectedIndex - 1].Selected = true; } } }
public void LoadThongTinHoaDon(int soLuongMon, double tongTien) { dgvHoaDon.Rows.Clear(); DataGridViewRowCollection collection = ((FrmBanHang)this.ParentForm).LayThongTinHoaDon(); bool valid = true; for (int i = 0; i < collection.Count; i++) { DataGridViewRow row1 = collection[i]; if (row1.Tag.GetType() == typeof(MonDTO)) { for (int j = i + 1; j < collection.Count; j++) { valid = true; DataGridViewRow row2 = collection[j]; if (row2.Tag.GetType() == typeof(MonDTO)) { for (int z = j + 1; z < collection.Count; z++) { valid = true; DataGridViewRow row3 = collection[z]; if (row3.Tag.GetType() == typeof(ToppingDTO)) { valid = false; j++; break; } else { valid = true; break; } } if (((MonDTO)row1.Tag).MaMon == ((MonDTO)row2.Tag).MaMon && valid) { int soLuong1 = Convert.ToInt32(row1.Cells["colSoLuong"].Value); int soLuong2 = Convert.ToInt32(row2.Cells["colSoLuong"].Value); row1.Cells["colSoLuong"].Value = soLuong1 + soLuong2;; collection.Remove(row2); j--; } } else { break; } } } } //DataGridViewRow rTemp = null; //for (int i = 0; i < collection.Count; i++) //{ // if (i + 1 < collection.Count) // { // if (collection[i+1].Tag.GetType() == typeof(ToppingDTO)) // { // continue; // } // else // { // DataGridViewRow row1 = collection[i]; // if (row1.Tag.GetType() == typeof(MonDTO)) // { // for (int j = i + 1; j < collection.Count; j++) // { // DataGridViewRow row2 = collection[j]; // if (row2.Tag.GetType() == typeof(MonDTO)) // { // if (j + 1 < collection.Count) // { // if (collection[j + 1].Tag.GetType() == typeof(MonDTO)) // { // if (((MonDTO)row1.Tag).MaMon == ((MonDTO)row2.Tag).MaMon) // { // int soLuong1 = Convert.ToInt32(row1.Cells["colSoLuong"].Value); // int soLuong2 = Convert.ToInt32(row2.Cells["colSoLuong"].Value); // row1.Cells["colSoLuong"].Value = soLuong1 + soLuong2; ; // rTemp = row1; // collection.Remove(row2); // } // } // } // else // { // if (((MonDTO)row1.Tag).MaMon == ((MonDTO)row2.Tag).MaMon) // { // int soLuong1 = Convert.ToInt32(row1.Cells["colSoLuong"].Value); // int soLuong2 = Convert.ToInt32(row2.Cells["colSoLuong"].Value); // row1.Cells["colSoLuong"].Value = soLuong1 + soLuong2; ; // collection.Remove(row2); // } // } // } // else // { // continue; // } // } // } // } // } // else // { // if (rTemp != null) // { // if (((MonDTO)collection[i].Tag).MaMon == ((MonDTO)rTemp.Tag).MaMon) // { // int soLuong1 = Convert.ToInt32(collection[i].Cells["colSoLuong"].Value); // int soLuong2 = Convert.ToInt32(rTemp.Cells["colSoLuong"].Value); // rTemp.Cells["colSoLuong"].Value = soLuong1 + soLuong2; ; // collection.Remove(collection[i]); // } // } // } //} foreach (DataGridViewRow row in collection) { DataGridViewRow r = (DataGridViewRow)row.Clone(); r.Cells[0].Value = row.Cells["colTenMon"].Value; r.Cells[1].Value = row.Cells["colSoLuong"].Value; r.Cells[2].Value = row.Cells["colDonGia"].Value; r.Cells[3].Value = row.Cells["colGhiChu"].Value; dgvHoaDon.Rows.Add(r); } dgvHoaDon.ClearSelection(); lblSoHoaDon.Text = "Mã hoá đơn: " + (HoaDonBUS.LayMaHoaDonMoiNhat() + 1); lblSoLuongMon.Text = "Số lượng món: " + soLuongMon + ""; lblTongTien.Text = "Tổng tiền: " + tongTien.ToString("#,##0đ"); }
private void btnCancel_Click(object sender, EventArgs e) { DataGridViewRowCollection rows = dataGridView1.Rows; rows.Remove(dataGridView1.CurrentRow); }