When trying to open one of my window forms in Visual Studio, I get this message box before the page loads: "Input string was not in a correct format". Once I click ok on that message box my page opens correctly with no errors showing.
On the window form that I'm loading I've got a ComboBox and a CheckedListBox, where I'm getting information from a data table in Sql Server.
Could the problem be the conversions I'm doing in my methods? And if so how can change them so that the message box does not appear any longer. I've read that try parse would be better but I'm not really sure how to apply that here.
void CheckList_Bikes()
{
int idcl = Convert.ToInt32(client.SelectedValue.ToString());
com.Parameters.Clear();
com.Parameters.AddWithValue("@idclient", idcl);
adaptb.Fill(biciT);
bikes.Items.Clear();
bikes.DataSource = biciT;
bikes.ValueMember = "ID";
bikes.DisplayMember = "name";
}
private void client_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
int idcl = Convert.ToInt32(client.SelectedValue.ToString());
com.Parameters.Clear();
com.Parameters.AddWithValue("@idclient", idcl);
bikes.Clear();
adaptb.Fill(biciT);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}