Juliano, I made a very simple example using the EntityFramework
as data source for the combo box, the complete code you can see here
I also took the opportunity to create an example in ASP.NET MVC, which you can see here
Popular the Combobox
private void Form1_Load(object sender, EventArgs e)
{
using (ComboBoxDBContext context = new ComboBoxDBContext())
{
comboBox1.DataSource = context.ProdutoGrupos.ToList();
comboBox1.ValueMember = "ProdutoGrupoId";
comboBox1.DisplayMember = "Descricao";
comboBox1.Refresh();
}
}
Recover the Selected Value
private void button1_Click(object sender, EventArgs e)
{
using (ComboBoxDBContext context = new ComboBoxDBContext())
{
Produto produto = new Produto();
produto.ProdutoGrupoId = Convert.ToInt32(comboBox1.SelectedValue);
produto.Descricao = textBox1.Text;
context.Produtos.Add(produto);
context.SaveChanges();
}
}
From experience of also being a programmer who left Delphi, I tell you to abstract a little the question of configuration by properties. Not that that’s not possible, but every time I tried to work on Windows Forms linking properties, I got a little frustrated.
It does. Take a look at this question.
– stderr