尝试从comboBox中检索值时出现int cast错误 [英] int casting error when trying to retrieve value from comboBox

查看:79
本文介绍了尝试从comboBox中检索值时出现int cast错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法找到一种方法将我的comboBox中的值转换为整数。我已经尝试了下面的


short iProjectID = Convert.ToInt16(cboProjects.SelectedValue);


i继续获取a不允许钉装铸造错误。我怎么能这样做?


tks

i can''t seem to find a way to cast the value in my comboBox to integer. i''ve
tried the following:
short iProjectID = Convert.ToInt16(cboProjects.SelectedValue);

i keep getting a "Sepcified cast is not allowed" error. how can i do this?

tks

推荐答案

>短的iProjectID = Convert.ToInt16(cboProjects .SelectedValue);


如果组合框包含字符串,请尝试


短iProjectID = Convert.ToInt16((string)cboProjects.SelectedValue);

Mattias


-

Mattias Sj?gren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com

请回复到新闻组。
>short iProjectID = Convert.ToInt16(cboProjects.SelectedValue);

If the combobox contains strings, try

short iProjectID = Convert.ToInt16((string)cboProjects.SelectedValue) ;
Mattias

--
Mattias Sj?gren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.


你确定你的SelectedValue属性实际设置为什么?

如果是这样......什么?


Brendan

Dica写道:
Are you sure that your SelectedValue property is actually set to something?
If so... what?

Brendan
"Dica" wrote:
我似乎无法找到一种方法将我的comboBox中的值转换为整数。我已经尝试了以下方法:
短的iProjectID = Convert.ToInt16(cboProjects.SelectedValue);

我一直得到一个不允许Sepcified cast错误。我该怎么做?

tks
i can''t seem to find a way to cast the value in my comboBox to integer. i''ve
tried the following:
short iProjectID = Convert.ToInt16(cboProjects.SelectedValue);

i keep getting a "Sepcified cast is not allowed" error. how can i do this?

tks





" Mattias Sj ?格伦" <毫安******************** @ mvps.org>在消息中写道

news:u5 ************** @ TK2MSFTNGP14.phx.gbl ...

"Mattias Sj?gren" <ma********************@mvps.org> wrote in message
news:u5**************@TK2MSFTNGP14.phx.gbl...
短的iProjectID = Convert.ToInt16(cboProjects.SelectedValue);
如果组合框包含字符串,请尝试

短的iProjectID = Convert.ToInt16((string)cboProjects.SelectedValue);
short iProjectID = Convert.ToInt16(cboProjects.SelectedValue);
If the combobox contains strings, try

short iProjectID = Convert.ToInt16((string)cboProjects.SelectedValue) ;




仍然无法正常工作。 selectedValue是dataSet中的整数。我还有

得到了演员错误。


Mattias

-
Mattias Sj?gren [ MVP] mattias @ mvps.org
http://www.msjogren.net/ dotnet / | http://www.dotnetinterop.com
请仅回复新闻组。



still doesn''t work. selectedValue is an integer from a dataSet. i''ve still
got a cast error.


Mattias

--
Mattias Sj?gren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.



这篇关于尝试从comboBox中检索值时出现int cast错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆