elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: ¿Eres nuevo? ¿Tienes dudas acerca del funcionamiento de la comunidad? Lee las Reglas Generales


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  Eliminar fila de un DataGrirdView enlazado a un array
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Eliminar fila de un DataGrirdView enlazado a un array  (Leído 1,672 veces)
leopaez

Desconectado Desconectado

Mensajes: 8


Ver Perfil
Eliminar fila de un DataGrirdView enlazado a un array
« en: 22 Mayo 2017, 21:10 pm »

Hola a todos, el programa es desarrollado en visual studio, windows Forms. Lo que se desea es buscar un registro para despues borrarlo. Las demas intrucciones; guardar y buscar estan ya desarrolladas. Solo faltaria eliminar.

Código
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11.  
  12. namespace Fase3_LeoPaez
  13. {
  14.  
  15.    public partial class Form1 : Form
  16.    {
  17.        ArrayList Personas = new ArrayList();
  18.        public Form1()
  19.        {
  20.            InitializeComponent();
  21.            Inhabilitar();
  22.        }
  23.  
  24.        private void registarToolStripMenuItem_Click(object sender, EventArgs e)
  25.        {
  26.            if (txtCedula.Text == "")
  27.            {
  28.                eperror.SetError(txtCedula, "Debe ingresar un numero de cedula");
  29.                txtCedula.Focus();
  30.                return;
  31.            }
  32.            eperror.SetError(txtCedula, "");
  33.  
  34.            decimal num;
  35.            if (!Decimal.TryParse(txtCedula.Text, out num))
  36.            {
  37.                eperror.SetError(txtCedula, "Debe ingresar un valor numerico");
  38.                txtCedula.Focus();
  39.                return;
  40.            }
  41.            eperror.SetError(txtCedula, "");
  42.  
  43.            if(Existe(txtCedula.Text))
  44.            {
  45.                eperror.SetError(txtCedula, "Esta cedula ya ha sido registrada");
  46.                txtCedula.Focus();
  47.                return;
  48.            }
  49.  
  50.            if (txtNombre.Text == "")
  51.            {
  52.                eperror.SetError(txtNombre, "Debe ingresar un Nombre");
  53.                txtNombre.Focus();
  54.                return;
  55.            }
  56.            eperror.SetError(txtNombre, "");
  57.  
  58.            if (txtCorreo.Text == "")
  59.            {
  60.                eperror.SetError(txtCorreo, "Debe ingresar un correo");
  61.                txtCorreo.Focus();
  62.                return;
  63.            }
  64.            eperror.SetError(txtCorreo, "");
  65.  
  66.            decimal numero;
  67.            if (!Decimal.TryParse(txtEdad.Text, out numero))
  68.            {
  69.                eperror.SetError(txtEdad, "Debe ingresar un valor numerico");
  70.                txtEdad.Focus();
  71.                return;
  72.            }
  73.            eperror.SetError(txtEdad, "");
  74.  
  75.            Persona_Leo miPersona = new Persona_Leo();
  76.            miPersona.Cedula = Decimal.Parse(txtCedula.Text);
  77.            miPersona.Nombre = txtNombre.Text;
  78.            miPersona.Email = txtCorreo.Text;
  79.            miPersona.Edad = Decimal.Parse(txtEdad.Text);
  80.            Personas.Add(miPersona);
  81.  
  82.            dgvDatos.DataSource = null;
  83.            dgvDatos.DataSource = Personas;
  84.  
  85.            Limpiar();
  86.            txtCedula.Focus();
  87.  
  88.  
  89.  
  90.  
  91.        }
  92.  
  93.        private bool Existe(string Cedula)
  94.        {
  95.          foreach (Persona_Leo Persona in Personas)
  96.            {
  97.                if (Persona.Cedula.ToString() == Cedula) return true;
  98.            }
  99.            return false;
  100.        }
  101.  
  102.        public void Limpiar()
  103.        {
  104.            txtCedula.Clear();
  105.            txtNombre.Clear();
  106.            txtCorreo.Clear();
  107.            txtEdad.Clear();
  108.        }
  109.  
  110.        public void Inhabilitar()
  111.        {
  112.            eliminarToolStripMenuItem.Enabled = false;
  113.         }
  114.  
  115.  
  116.  
  117.  
  118.        private void salirToolStripMenuItem_Click(object sender, EventArgs e)
  119.        {
  120.            Application.Exit();
  121.        }
  122.  
  123.        private void eliminarToolStripMenuItem_Click(object sender, EventArgs e)
  124.        {
  125.            if (Personas.Count != 0)
  126.            {
  127.  
  128.  
  129.                MessageBox.Show("Se elimino el registro", "Atención");
  130.                Limpiar();
  131.            }
  132.            else
  133.            {
  134.                MessageBox.Show("La lista esta vacia", "Atención");
  135.                Limpiar();
  136.            }
  137.        }
  138.  
  139.        private void buscarToolStripMenuItem_Click(object sender, EventArgs e)
  140.        {
  141.            if (txtCedula.Text == "")
  142.            {
  143.                eperror.SetError(txtCedula, "Debe ingresar una cedula");
  144.                txtCedula.Focus();
  145.                return;
  146.            }
  147.            eperror.SetError(txtCedula, "");
  148.  
  149.            Persona_Leo miPersona = Obtener(txtCedula.Text);
  150.            if (miPersona == null)
  151.            {
  152.                eperror.SetError(txtCedula, "El Trabajador no existe");
  153.                txtCedula.Focus();
  154.                return;
  155.            }
  156.            eperror.SetError(txtCedula, "");
  157.  
  158.            txtCedula.Text = miPersona.Cedula.ToString();
  159.            txtNombre.Text = miPersona.Nombre;
  160.            txtCorreo.Text = miPersona.Email;
  161.            txtEdad.Text = miPersona.Edad.ToString();
  162.            eliminarToolStripMenuItem.Enabled = true;
  163.        }
  164.  
  165.            private Persona_Leo Obtener(String Cedula)
  166.        {
  167.            foreach (Persona_Leo miPersona in Personas)
  168.            {
  169.                if (miPersona.Cedula.ToString() == Cedula) return miPersona;
  170.            }
  171.            return null;
  172.        }
  173.  
  174.        private void limpiarToolStripMenuItem_Click(object sender, EventArgs e)
  175.        {
  176.            Limpiar();
  177.        }
  178.  
  179.  
  180.    }
  181.  
  182. }
  183.  



En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
duda de eliminar fila en vba para excel
Programación Visual Basic
Railil 5 7,903 Último mensaje 15 Noviembre 2006, 13:12 pm
por Railil
Eliminar Fila de un Datagrid View usando valor de un inputbox
.NET (C#, VB.NET, ASP)
syaoran 1 5,066 Último mensaje 23 Abril 2008, 06:24 am
por rain_in!the!_universe
Eliminar Fila De Jtable(Jtabla Sin Model)
Java
ZedGe 4 5,158 Último mensaje 29 Noviembre 2011, 23:35 pm
por ZedGe
Seleccionar una fila de un array en C
Programación C/C++
folostia 6 5,851 Último mensaje 15 Enero 2012, 18:25 pm
por rir3760
Eliminar las posiciones pares de un array y comprimir el array
Java
sevedeboa 8 14,767 Último mensaje 26 Enero 2015, 15:52 pm
por sevedeboa
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines