0
How do I add an item to the Combobox?
The item has to be the first on the list with the text "SELECT":
I’m doing like this:
private void PreencherCmbIndicacao()
{
try
{
this.cmbIndicacao.Items.Clear();
this.cmbIndicacao.DataSource = ListarIndicacao();
this.cmbIndicacao.ValueMember = "IDPACIENTE";
this.cmbIndicacao.DisplayMember = "NOME";
this.cmbIndicacao.Items.Insert(0, "SELECIONE");
//this.cmbIndicacao.Text = "SELECIONE";
}
catch (Exception e)
{
throw new Exception("Erro ao listar Indicação do Paciente: " + e.Message);
}
}
And this error occurs: Cannot modify item collection when Datasource property is set.
private static DataTable ListarIndicacao()
{
try
{
DataTable dt = PacienteNegocio.ObterIndicacao();
return dt;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
This is the method of access to the Bank:
public static DataTable ObterIndicacao()
{
try
{
OleDbConnection conn = new OleDbConnection(Conexao.obterConexao());
conn.Open();
OleDbDataAdapter da = new OleDbDataAdapter("Select IDPACIENTE, NOME From TBPaciente WHERE NOME IS NOT NULL ORDER BY NOME", conn);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
catch (Exception ex)
{
throw new Exception("Erro ao listar dados de Indicação: " + ex.Message);
}
}
put the method code
ListarIndicacao
– Rovann Linhalis
Ready put
– hard123