It's been so long since I was working with WinForms that I'm letting something go. In Load from my Form I call this method below:
private void CarregarEstados()
{
cboEstado.DataSource = Listas.ListaEstados();
cboEstado.DisplayMember = "UF";
}
public static DataTable ListaEstados()
{
DataTable _table = null;
try
{
var _connector = GetSQLInstance.getInstance();
_table = _connector.GetTable(CommandType.StoredProcedure, "SPL_CREDENCIADOS_UF_PESQUISA");
}
catch (Exception Error)
{
LastErrorCode = MazeFire.ErrorManager.GetErrorCode(Error);
LastErrorObject = Error;
LastError = Error.Message;
}
return _table;
}
The called method returns a DataTable with a column called UF. It loads the combo smoothly.
However, I was asked to automatically load the Cities and Neighborhoods that are available in the DB. So, I do this in the event below:
private void cboEstado_SelectedIndexChanged(object sender, EventArgs e)
{
// Assim o Combo sempre retorna vazio
CarregarCidades(cboEstado.SelectedText);
}
private void CarregarCidades(string estado)
{
cboCidade.DataSource = Listas.ListaCidades(estado);
cboCidade.DisplayMember = "Cidade";
}
My problem occurs when calling the LoadCities, because I can not get the value set in the cboEstado (in case SP).
Here in the example it is as cboEstado.SelectedText
passing "" to the method, but I already tried cboEstado.SelectedValue.ToString()
and cboEstado.SelectedItem.ToString()
and both pass System.Data.DataRowView
as parameter.
Could you explain what I'm letting go?
Thank you.