I have a ComboBox filled in from a list created with information obtained from a txt file. But instead of being filled with the information of the file he is receiving inside it ----- > GeraRelatorio.Planta
, would you like to know why?
private void Form1_Load(object sender, EventArgs e)
{
dateInicial.Value = DateTime.Today.AddDays(-1);
dateFinal.Value = DateTime.Today.AddDays(-1);
textBox1.MaxLength = 20;
comboBanco.Items.Clear();
List<Planta> plantas = new List<Planta>();
using (StreamReader arquivo = File.OpenText(@"C:\Conexoes\Estados.txt"))
{
string linha;
while ((linha = arquivo.ReadLine()) != null)
{
var espaçoArquivo = linha.Split(';');
var planta = new Planta();
planta.Local = espaçoArquivo[0];
planta.Conexao = espaçoArquivo[1];
plantas.Add(planta);
}
}
foreach (Planta result in plantas)
{
comboBanco.Items.Add(result);
}
}
private void comboBanco_SelectedIndexChanged(object sender, EventArgs e)
{
comboBanco.SendToBack();
FrmGrid formb = new FrmGrid();
switch (((Planta)comboBanco.SelectedItem).Local)
{
case "CT":
formb.lblLocal.Text = ((Planta)comboBanco.SelectedItem).Local;
formb.lblConexao.Text = ((Planta)comboBanco.SelectedItem).Conexao;
formb.Show();
break;
case "CU":
formb.lblLocal.Text = ((Planta)comboBanco.SelectedItem).Local;
formb.lblConexao.Text = ((Planta)comboBanco.SelectedItem).Conexao;
formb.Show();
break;
case "AT":
formb.lblLocal.Text = ((Planta)comboBanco.SelectedItem).Local;
formb.lblConexao.Text = ((Planta)comboBanco.SelectedItem).Conexao;
formb.Show();
break;
default:
break;
}
}
class Planta
{
public string Local { get; set; }
public string Conexao { get; set; }
}