Example #1
0
        private void btnEliminar_Click(object sender, EventArgs e)
        {
            if (rolesDataGridView.SelectedRows == null || rolesDataGridView.SelectedRows.Count == 0)
            {
                return;
            }
            var row = rolesDataGridView.SelectedRows[0];
            var rol = row.DataBoundItem as Rol;

            if (MessageBox.Show(string.Format("Confirma que desea eliminar el rol {0}?", rol.Nombre)
                                , "Eliminar rol", MessageBoxButtons.OKCancel) == DialogResult.OK)
            {
                try
                {
                    rolesManager.BorrarRol(rol);
                    var dataSource = rolesDataGridView.DataSource as BindingList <Rol>;
                    dataSource.Remove(rol);
                    rolesDataGridView.Refresh();
                    lblResults.Text = dataSource.Count.ToString();
                    MessageBox.Show(string.Format("Rol {0} eliminado", rol.Nombre));
                }
                catch (System.Exception excep)
                {
                    MessageBox.Show(excep.Message);
                }
            }
        }