Foro de elhacker.net

Programación => .NET (C#, VB.NET, ASP) => Mensaje iniciado por: SAGA-gl en 1 Junio 2015, 05:04 am



Título: validar registro de datagrid
Publicado por: SAGA-gl en 1 Junio 2015, 05:04 am
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
Código
  1. private void button1_Click(object sender, EventArgs e)
  2.        {
  3.            if (txtCantidad.Text == "" || txtPrograma.Text == "" || txtPrecio.Text == "")
  4.            {
  5.  
  6.                DialogResult ds = MessageBox.Show(this, "DEBE COMPLETAR TODOS LOS CAMPOS", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  7.                this.Text = ds.ToString();
  8.  
  9.            }
  10.            else
  11.  
  12.                if (txtCantidad.Text != "" || txtPrograma.Text != "" || txtPrecio.Text != "")
  13.                {
  14.  
  15.                    int numero = int.Parse(txtNumero.Text);
  16.                    string medicamento = comboMedicamento.Text;
  17.                    int cantidad = int.Parse(txtCantidad.Text);
  18.                    string programa = txtPrograma.Text;
  19.                    float precio = float.Parse(txtPrecio.Text);
  20.                    int numMedic = int.Parse(comboMedicamento.SelectedValue.ToString());
  21.                    bool existe = dgv.Rows.Cast<DataGridViewRow>().Any(x => Convert.ToInt32(x.Cells["Column7"].Value) == numMedic);
  22.  
  23.                    if (existe)
  24.                    {
  25.  
  26.                        MessageBox.Show(this, "MEDICAMENTO YA CARGADO", "ATENCION", MessageBoxButtons.OK);
  27.  
  28.                    }
  29.                    else
  30.                    {
  31.                        if (!existe)
  32.                        {
  33.                            dgv.Rows.Add(numMedic, medicamento, cantidad, programa, precio, cantidad * precio, numero);
  34.                            button2.Enabled = true;
  35.                            button3.Enabled = true;
  36.                            txtCantidad.Text = "";
  37.                            txtPrecio.Text = "";
  38.                            txtPrograma.Text = "";
  39.                        }
  40.                    }
  41.                }
  42.  
  43.        }


Título: Re: validar registro de datagrid
Publicado por: SAGA-gl en 1 Junio 2015, 05:14 am
disculpen....lo pude resolver mil grax perdón x las molestias


Título: Re: validar registro de datagrid
Publicado por: nolasco281 en 2 Junio 2015, 03:40 am
Hola SAGA-gl seria bueno que nos comentaras (por lo menos a mi) que estabas haciendo mal puede que a alquien le sirva.

Saludos.