My code goes like this for simple practise problem which i am trying to build. I come across
Invalid Cast Exception. Specified Cast is not valid.
public Form1()
{
Combobox1.Datasource = foo.bar.dataset.tables[0];
Combobox1.DisplayMember = "Name";
Combobox1.ValueMember = "ID";
}
private void ComboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
NewClass P2 = new NewClass;
P2.Filter.Id = (long)Combobox1.SelectedValue;
}
Can anyone tell me why is this happening and how to go about solving it even though I have typecasted Combobox1.SelectedValue object?
Maybe this will help:
According to your comment this might help: