我有一个使用字典作为数据源的列表框。
当我想将列表框的 selectedvalue 解析为 int 变量时,它给了我一个强制转换异常。
字典~
Dictionary<int, string> AssetDictionary = new Dictionary<int, string>();
列表框(lstAsset)数据源~
lstAsset.DisplayMember = "Value";
//lstAssetType.ValueMember = "Key"; //This should be lstAsset as corrected in the next line
lstAsset.ValueMember = "Key";
lstAsset.DataSource = new BindingSource(AssetDictionary, null);
发生异常的那一行~
int ush = (int)lstAsset.SelectedValue; //Specified cast is not valid.
我在哪里做错了?