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 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 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 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 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 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 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 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; } } }
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; } } }
private void dataGridView1_CellContentClick_1(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == 0) { int cantitate = 1; try { cantitate = int.Parse(this.dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString()); } catch (Exception ex) { MessageBox.Show("Enter the Quantity"); return; } if (cantitate < 1) { MessageBox.Show("Negative amount"); return; } int pret = int.Parse(this.dataGridView1.Rows[e.RowIndex].Cells[5].Value.ToString()); int kcal = int.Parse(this.dataGridView1.Rows[e.RowIndex].Cells[6].Value.ToString()); pret *= cantitate; kcal *= cantitate; int pret_curent = int.Parse(this.textBox_PretTotal.Text); int kcal_curent = int.Parse(this.textBox_totalKcal.Text); pret_curent += pret; kcal_curent += kcal; this.textBox_totalKcal.Text = kcal_curent.ToString(); this.textBox_PretTotal.Text = pret_curent.ToString(); //--------------------------------------------------- frmViz.textBox_NecesarZilnic_e.Text = this.textBox_NecesarZilnic.Text; frmViz.textBox_totalKcal_e.Text = this.textBox_totalKcal.Text; frmViz.textBox_PretTotal_e.Text = this.textBox_PretTotal.Text; //---------------------------------------------------- int index = frmViz.dataGridView_e.Rows.Count; index--; DataGridViewRowCollection row = frmViz.dataGridView_e.Rows; string[] ob = new string[5]; ob[0] = this.dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString(); ob[1] = this.dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString(); ob[2] = this.dataGridView1.Rows[e.RowIndex].Cells[6].Value.ToString(); ob[3] = this.dataGridView1.Rows[e.RowIndex].Cells[5].Value.ToString(); ob[4] = this.dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString(); row.Insert(index, ob); } }
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; }
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 { } }
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; } }
/// <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); } //} } }
/// <summary> /// Insert the specified object to this DataGridView. /// If <paramref name="index"/> greater than or equals the count of rows, then append this object to this DataGridView. /// </summary> /// <param name="info">A <typeparamref name="T"/> object.</param> /// <param name="index">The position to insert.</param> /// <exception cref="System.ArgumentException"><paramref name="info"/> is null.</exception> /// <exception cref="System.ArgumentException"><paramref name="index"/> is less than zero.</exception> public virtual void Insert(T info, int index) { if (info == null) { throw new ArgumentException("info is null", "info"); } if (index < 0) { throw new ArgumentException("index is less than zero.", "index"); } DataGridViewRowCollection rows = this.DataGridView.Rows; if (rows.Count == 0) { index = 0; } else if (index >= rows.Count) { index = rows.Count; } rows.Insert(index); this.FillRow(info, rows[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; } } }
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; } }