如何在组合框中获取整数值 [英] How to get value in combo box as integer

查看:62
本文介绍了如何在组合框中获取整数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友们,



我正在设计一个用于GPA计算的winForm。



查看image :: https://lh6.googleusercontent.com/-d1n8iNQekCo /UccAuc7Te1I/AAAAAAAAB10/fnZCnZVGDxo/w493-h551-no/issue.png [ ^ ]



检查等级组合框。



如果用户选择s,a等程序,应将这些值设为5,4等。



如何在代码中实现。



还给我任何建议以简单的方式实现这一点..



能够点击图片的链接 - ProgramFOX [/ Edit]

解决方案





使用词典

http:// msdn .microsoft.com / zh-CN / library / xfhwa508.aspx [ ^ ]

字典< string,int> integers =  new  Dictionary< string,int>(); 
public Form1()
{
InitializeComponent();
integers.Add( S 5 );
integers.Add( A 4 );
// 为您的所有值执行此操作
}



当您从所选选项中获取int值时:

  int  intValue =整数[( string )yourComboBox.SelectedItem]; 



希望这会有所帮助。


将DDL的Text属性填充为所需的字符串,并在Value属性中对应Integer值,并在代码中获取此整数值,并将其用于其他编码方式。



因为您的DDL ID为id =grade然后



 int GradeValue = int。解析(grade.Value); 


Dear Friends,

I am designing a winForm for GPA Calculation.

check out the image :: https://lh6.googleusercontent.com/-d1n8iNQekCo/UccAuc7Te1I/AAAAAAAAB10/fnZCnZVGDxo/w493-h551-no/issue.png[^]

Check that grade combo box.

If user select 's' , 'a' etc. program should get these values as '5' , '4' etc..

How to implement in code.

Also give me any suggestion to implement this in easy way..

[Edit]Made able to click on the link to the image - ProgramFOX[/Edit]

解决方案

Hi,

Use a Dictionary:
http://msdn.microsoft.com/en-us/library/xfhwa508.aspx[^]

Dictionary<string, int> integers = new Dictionary<string, int>();
public Form1()
{
     InitializeComponent();
     integers.Add("S", 5);
     integers.Add("A", 4);
     // do this for all your values
}


And when you should get the int value from the selected option:

int intValue = integers[(string)yourComboBox.SelectedItem];


Hope this helps.


Fill the Text property of DDL as string that you want and in the Value property corresponding Integer value and get this integer value in your code and use this for furthere coding manner.

as your DDL id is as id="grade" then

int GradeValue=int.Parse(grade.Value);


这篇关于如何在组合框中获取整数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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