private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { var senderGrid = (DataGridView)sender; if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn && e.RowIndex >= 0) { if (senderGrid.Columns[e.ColumnIndex].Name.Equals("ColumnModificar")) { Consumible cons = new Consumible { codigoConsumible = senderGrid.Rows[e.RowIndex].Cells[0].Value.ToString(), descripcion = senderGrid.Rows[e.RowIndex].Cells[1].Value.ToString(), precio = senderGrid.Rows[e.RowIndex].Cells[2].Value.ToString() }; var cantidadSelector = new SelectCantidad(cons, Convert.ToInt32(senderGrid.Rows[e.RowIndex].Cells[3].Value.ToString())); if (cantidadSelector.ShowDialog(this) == System.Windows.Forms.DialogResult.OK) { senderGrid.Rows[e.RowIndex].Cells[3].Value = cantidadSelector.CantidadElegida; senderGrid.Rows[e.RowIndex].Cells[4].Value = CalcSubTotal(senderGrid.Rows[e.RowIndex].Cells[2].Value.ToString(), cantidadSelector.CantidadElegida).ToString(); dataGridView1_RowsAltered(null, null); } } else if (senderGrid.Columns[e.ColumnIndex].Name.Equals("ColumnRemove")) { dataGridView1.Rows.RemoveAt(e.RowIndex); } } }
private void buttonAdd_Click(object sender, EventArgs e) { var selector = new SeleccionadorConsumible(); if (selector.ShowDialog(this) == System.Windows.Forms.DialogResult.OK) { Consumible consumible = selector.ConsumibleSeleccionado; var cantidadSelector = new SelectCantidad(consumible); if (cantidadSelector.ShowDialog(this) == System.Windows.Forms.DialogResult.OK) { this.dataGridView1.Rows.Add(consumible.codigoConsumible, consumible.descripcion, consumible.precio, cantidadSelector.CantidadElegida, CalcSubTotal(consumible.precio, cantidadSelector.CantidadElegida), "Modificar", "Remover"); } } }