Good morning, first of all I would like to say that I am a beginner and I am doubtful about assigning a value to the Text
property of a Label
from a list created with information obtained from a txt
.
Follow the code:
namespace BetaTeste
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void Form1_Load(object sender, EventArgs e)
{
comboBox1.Items.Clear();
List<Planta> plantas = new List<Planta>();
using (StreamReader arquivo = File.OpenText(@"C:\Estados\Banco de 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)
{
comboBox1.Items.Add(result.Local);
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
FrmBase formb = new FrmBase();
switch (comboBox1.SelectedItem.ToString().Trim())
{
case "CT":
formb.Show();
// aqui está a dúvida
// formb.lblLocal.Text = ;
break;
}
}
}
}
--------------------------------------------------------------------------------
class Planta
{
public string Local { get; set; }
public string Conexao { get; set; }
public void Pesquisa()
{
}
}
--------------------------------------------------------------------------------
public partial class FrmBase : Form
{
public FrmBase()
{
InitializeComponent();
}
}
The goal is to fill Label
with the value of a property of class Planta
, but I'm not sure how I can get information from classes listed in items
of ComboBox
.
The% w_that I want to assign the value is label
(line in comment).