The function of this code is to read the information: Name of the course, 4 grades and the average
The problem: I can not transport the data in a List on Form Cadastrar
and display information on Form Exibir
.
Form Code Menu
:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SimuladorFMM
{
public partial class Menu : Form
{
public Menu()
{
InitializeComponent();
}
private void cadastrarMenu_Click(object sender, EventArgs e)
{
Cadastro abrirCadastro = new Cadastro();
abrirCadastro.ShowDialog();
}
private void botaoExibir_Click(object sender, EventArgs e)
{
Exibir abrirExibir = new Exibir();
abrirExibir.ShowDialog();
}
}
}
Form Code of Cadastro
:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SimuladorFMM
{
public partial class Cadastro : Form
{
public Cadastro()
{
InitializeComponent();
}
private void finalizar_Click(object sender, EventArgs e)
{
List<Disciplina> dados = new List<Disciplina>();
Disciplina entrada = new Disciplina();
entrada.nome = nomeCadastro.Text;
entrada.nota[0] = Convert.ToDouble(nota1.Text);
entrada.nota[1] = Convert.ToDouble(nota2.Text);
entrada.nota[2] = Convert.ToDouble(nota3.Text);
entrada.nota[3] = Convert.ToDouble(nota4.Text);
entrada.media = (entrada.nota[0] + entrada.nota[1] + entrada.nota[2] + entrada.nota[3]) / 4;
dados.Add(entrada);
}
}
}
Form Code Exibir
:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SimuladorFMM
{
public partial class Exibir : Form
{
int i = 0;
public Exibir()
{
InitializeComponent();
}
private void Exibir_Load(object sender, EventArgs e)
{
}
private void proximo_Click(object sender, EventArgs e)
{
if (i < dados.Count)
{
i++;
exibirNome.Text = dados[i].nome;
exibirNota1.Text = dados[i].nota[0].ToString();
exibirNota2.Text = dados[i].nota[1].ToString();
exibirNota3.Text = dados[i].nota[2].ToString();
exibirNota4.Text = dados[i].nota[3].ToString();
exibirMedia.Text = dados[i].media.ToString();
}
}
private void anterior_Click(object sender, EventArgs e)
{
if (i > 0)
{
i--;
exibirNome.Text = dados[i].nome;
exibirNota1.Text = dados[i].nota[0].ToString();
exibirNota2.Text = dados[i].nota[1].ToString();
exibirNota3.Text = dados[i].nota[2].ToString();
exibirNota4.Text = dados[i].nota[3].ToString();
exibirMedia.Text = dados[i].media.ToString();
}
}
}
}