Help with the error:
'System.FormatException' in mscorlib.dll. Additional information: The input string does not have the correct format.
I have an error when I start my frame for the first time since I have ComboBox
nested State, Municipality and Location. The last two are updated with events. Municipality is updated when something changes in State, and Location is updated when there is a change in Municipality.
My problem occurs when the ComboBox
Status is filled for the first time, since I imagine that the event cmbEstado_SelectedValueChanged
of ComboBox
is activated from behind and therefore there is an error in Municipality since it does not recognize the property cmbEstado.ValueMember
, which should be the state id. But it is only the first time. Since after loading it does not give me the error anymore.
This is the state filling code
try
{
List<Estado> estados = ctrl.llenarDataSource<Estado>().ToList();
cmbEstado.DisplayMember = "stNombre";
cmbEstado.ValueMember = "id";
cmbEstado.DataSource = estados;
}
catch (Exception ex)
{
ctrl.msjError(ex.Message + " " + ex.Source);
}
And this one of Municipality
try
{
cmbMunicipio.DataSource = ctrl.consultarConID<Municipio>("idEstado", int.Parse(cmbEstado.SelectedValue.toString()));
cmbMunicipio.DisplayMember = "stNombre";
cmbMunicipio.ValueMember = "id";
}
catch (Exception)
{
}
As you will see I mitigate the error with the empty Catch so that it does not do anything, however, I consider that it is not the best thing to do that. Does anyone have any suggestions?