I need help with this part of my code. I'm trying to do 2 things here:
1st, I need my comboBox cmbTechSearch filled with a list of names retrieved from a SQL database. Those names belong to an object called Tecnico. So far, so good. But if I click on the comboBox twice, I get the names duplicated... And so on. Adding cmbTechSearch.Items.Clear(); didn't solve it because the box was data binded, firing an error message. So I added cmbTechSearch.DataSource = null; which solved the error message but didn't clear my box. Nor did cmbTechSearch.ResetText(); Right now I'm unsure about how to clear it so that data doesn't come duplicated if I click the box again.
2nd, that list retrieved from SQL database brings more than just the name attached. It brings an e-mail for each object too. And I can't figure out how to retrieve the mail associated to the chosen name on that comboBox. Mind you, email is a global string var since I use it in other methods within the code. That part is commented because it doesn't work.
public void TechSearch_loaded(object sender, EventArgs e)
{
//all these 3 entries are supposedly to clear the comboBox cmbTechSearch; all of them fail but if I remove the 1st line I get an error saying that there's already some data bound to the box (but only if I click a 2nd time)
cmbTechSearch.DataSource = null;
cmbTechSearch.Items.Clear();
cmbTechSearch.ResetText();
//there's a class called Tecnico and all the info about that object is saved on a SQL db. This part populates a list of Tecnicos with info from the db.
List<Tecnico> tecnicos = new List<Tecnico>();
tecnicos = bd.ProcuraPerfisTipo("TEC");
//then I get a list of Tecnicos and retrieve one attribute (Nome) for each tecnico in the list
List<String> TechSearch = new List<String>();
foreach (Tecnico obj in tecnicos)
{
TechSearch.Add(obj.Nome);
}
//lastly I populate the comboBox with the info I got from the list.
cmbTechSearch.DataSource = TechSearch;
//email = cmbTechSearch.ToString();
}
There's a class named Tecnico, another named BDTicketSQL and another named iBDTicketSQL (the first calling the SQL db and running updates, queries and inserts while the second is used for interface). Those classes are all external to this form. I just get date from them to populate the form with whatever info I need.