buenas noches gente del foro....tengo el siguiente código en el cual a partir de un botón voy agregando registros a un datagridview e intento no dejar agregar otro registro que tenga igual el campo medicamento si ya esta cargado....al final no lo puedo conseguir ya q no m deja agregar uno repetido pero qando cambio el medicamento o sea es distinto...no m lo deja agregar...q tngo q modificar del bool? muchas grax d antemano
private void button1_Click(object sender, EventArgs e)
{
if (txtCantidad.Text == "" || txtPrograma.Text == "" || txtPrecio.Text == "")
{
DialogResult ds = MessageBox.Show(this, "DEBE COMPLETAR TODOS LOS CAMPOS", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
this.Text = ds.ToString();
}
else
if (txtCantidad.Text != "" || txtPrograma.Text != "" || txtPrecio.Text != "")
{
int numero = int.Parse(txtNumero.Text);
string medicamento = comboMedicamento.Text;
int cantidad = int.Parse(txtCantidad.Text);
string programa = txtPrograma.Text;
float precio = float.Parse(txtPrecio.Text);
int numMedic = int.Parse(comboMedicamento.SelectedValue.ToString());
bool existe = dgv.Rows.Cast<DataGridViewRow>().Any(x => Convert.ToInt32(x.Cells["Column7"].Value) == numMedic);
if (existe)
{
MessageBox.Show(this, "MEDICAMENTO YA CARGADO", "ATENCION", MessageBoxButtons.OK);
}
else
{
if (!existe)
{
dgv.Rows.Add(numMedic, medicamento, cantidad, programa, precio, cantidad * precio, numero);
button2.Enabled = true;
button3.Enabled = true;
txtCantidad.Text = "";
txtPrecio.Text = "";
txtPrograma.Text = "";
}
}
}
}
disculpen....lo pude resolver mil grax perdón x las molestias
Hola SAGA-gl seria bueno que nos comentaras (por lo menos a mi) que estabas haciendo mal puede que a alquien le sirva.
Saludos.