How do I add an item in the Combobox?
The item has to be first in the list with the text "SELECT":
I'm doing 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: Can not modify collection of items when DataSource property is set.
privatestaticDataTableListarIndicacao(){try{DataTabledt=PacienteNegocio.ObterIndicacao();returndt;}catch(Exceptionex){thrownewException(ex.Message);}}
ThisisthemethodofaccessingtheBank:
publicstaticDataTableObterIndicacao(){try{OleDbConnectionconn=newOleDbConnection(Conexao.obterConexao());conn.Open();OleDbDataAdapterda=newOleDbDataAdapter("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);
}
}