Test Foro de elhacker.net SMF 2.1

Programación => Programación General => .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 (csharp) [Seleccionar]
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 = "";
                        }
                    }
                }

        }
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.