如何使用组合框选择的索引作为int [英] how to use the combobox selected index as int

查看:64
本文介绍了如何使用组合框选择的索引作为int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private void BaudRate_SelectedIndexChanged(object sender, EventArgs e)
       {
           if ((CamPort.IsOpen)) CamPort.Close();
           if (BaudRate.SelectedIndex == -1) return;
           if (string.IsNullOrWhiteSpace(BaudRate.Text)) return;
           //CamPort.BaudRate =(int)BaudRate.Text;
           CamPort.Open();

       }

推荐答案

从您的代码看起来您​​真正想要的是解析所选的值,如所以:

From your code it looks like what you really want is to parse the selected value like so:
CamPort.BaudRate = int.Parse(BaudRate.Text);





如果您想使用所选索引作为标题建议,那么您只需使用它:



If you wanted to use the selected index as your title suggests then you would just use it:

CamPort.BaudRate = BaudRate.SelectedIndex



...但是你的值只有0,1,2等


...But then your value would only be 0,1,2,etc


这篇关于如何使用组合框选择的索引作为int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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