Hi,
I am having a listbox in my WinForm application that I am filling up with items like this:
List<Metadata> allMetadata = Metadata.GetAllMetadata();
lbxAllMetadata.DataSource = allMetadata;
lbxAllMetadata.DisplayMember = "Name";
lbxAllMetadata.ValueMember = "Id";
In the SelectedIndexChanged event from that listbox I applied the following code:
private void lbxAllMetadata_SelectedIndexChanged(object sender, EventArgs e)
{
if (lbxAllMetadata.SelectedIndex != -1)
{
label1.Text = ">" + lbxAllMetadata.SelectedValue.ToString() + "<";
CurrentItem = Metadata.GetMetadata(Convert.ToInt32(lbxAllMetadata.SelectedValue.ToString()));
}
}
Unfortunately this runs into a runtime exception saying:
An exception of type 'System.FormatException' occurred in mscorlib.dll but was not handled in user code
What am I doing wrong? How can I get the int-value of the ValueMember property from the listbox?