Martinho Neves
New member
- Joined
- May 18, 2018
- Messages
- 2
- Programming Experience
- 1-3
Hello to all
I am having a bit of difficulty to find a solution to a problem.
I have a database with a table called tAno.
The structure of the table is as follows.
I populate this table to a combo box like this:
cl_GestorBD gestor = new cl_GestorBD(VerifInicial.CFBDados);
string query = "SELECT * FROM tAno";
DataTable dados = gestor.EXE_READER(query);
NumRegistos = dados.Rows.Count;
Cbox_Ano.DisplayMember = "Value";
Cbox_Ano.ValueMember = "Id";
for (int i = 0; i < NumRegistos; i++)
{
Cbox_Ano.Items.Add(new { Value = dados.Rows["Ano"], Id = dados.Rows["IdAno"] });
}
Cbox_Ano.Sorted = true;
}
-----------------------------------------------------------------------
I retrieve the date from the combobox if I choose the first year:
private void Cbox_Ano_TextChanged(object sender, EventArgs e)
{
Console.WriteLine(Cbox_Ano.SelectedItem.ToString());
}
The output is: { Value = 2010, Id = 1 }
How can I get an output similar to:
SelectedValue=2010
SelectedId = 1
Thank you in advance for any help you can give me.
I am having a bit of difficulty to find a solution to a problem.
I have a database with a table called tAno.
The structure of the table is as follows.
IdAno | Ano |
1 | 2010 |
2 | 2011 |
3 | 2012 |
4 | 2013 |
5 | 2014 |
6 | 2015 |
7 | 2016 |
8 | 2017 |
9 | 2018 |
I populate this table to a combo box like this:
cl_GestorBD gestor = new cl_GestorBD(VerifInicial.CFBDados);
string query = "SELECT * FROM tAno";
DataTable dados = gestor.EXE_READER(query);
NumRegistos = dados.Rows.Count;
Cbox_Ano.DisplayMember = "Value";
Cbox_Ano.ValueMember = "Id";
for (int i = 0; i < NumRegistos; i++)
{
Cbox_Ano.Items.Add(new { Value = dados.Rows["Ano"], Id = dados.Rows["IdAno"] });
}
Cbox_Ano.Sorted = true;
}
-----------------------------------------------------------------------
I retrieve the date from the combobox if I choose the first year:
private void Cbox_Ano_TextChanged(object sender, EventArgs e)
{
Console.WriteLine(Cbox_Ano.SelectedItem.ToString());
}
The output is: { Value = 2010, Id = 1 }
How can I get an output similar to:
SelectedValue=2010
SelectedId = 1
Thank you in advance for any help you can give me.