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.
[TABLE="class: grid, width: 300"]
[TR]
[TD]IdAno[/TD]
[TD]Ano[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]2010[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]2011[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]2012[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]2013[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]2014[/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]2015[/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD]2016[/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD]2017[/TD]
[/TR]
[TR]
[TD]9[/TD]
[TD]2018[/TD]
[/TR]
[/TABLE]
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.
[TABLE="class: grid, width: 300"]
[TR]
[TD]IdAno[/TD]
[TD]Ano[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]2010[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]2011[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]2012[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]2013[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]2014[/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]2015[/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD]2016[/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD]2017[/TD]
[/TR]
[TR]
[TD]9[/TD]
[TD]2018[/TD]
[/TR]
[/TABLE]
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.