刷新c#中组合框的值 [英] refresh value of combo box in c#

查看:59
本文介绍了刷新c#中组合框的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有一些组合框,我怎么能刷新它们?

它可以通过串口工作!当我连接到微控制器并接收一些数据时,根据这些数据选择组合框上的值。但当我选择组合框的特殊值,并通过串口再次连接时,组合框的值没有改变!

for ex。

hi i have some comboboxes, how can i refresh them?
it works by serial port! when i connect to a microcontroller and receive some data, according to these data select a value on combobox. but when i select special value of combobox, and connect again by serial port, the value of combobox have not been changed!
for ex.

serialPort1.Read(uploaddone, 0, uploaddone.Length);
if ((uploaddone[30] & 0x01) == 0x01)
{
   if ((uploaddone[30] & 0x06) == 0x00) comboBox42.SelectedIndex = 0;
   if ((uploaddone[30] & 0x08) == 0x02) comboBox43.SelectedIndex = 1;
   comboBox45.Hide();comboBox46.Hide();
}

if ((uploaddone[30] & 0x01) == 0x00)
{
   if ((uploaddone[30] & 0x06) == 0x00) comboBox45.SelectedIndex = 0;
   if ((uploaddone[30] & 0x08) == 0x02) comboBox46.SelectedIndex = 1;
   comboBox42.Hide();comboBox43.Hide();
}



如何修复它?


how can i repair it?

推荐答案

if ((uploaddone[30] & 0x08) == 0x02) comboBox43.SelectedIndex = 1;




if ((uploaddone[30] & 0x08) == 0x02) comboBox46.SelectedIndex = 1;



这些都不会是真的。


Neither of these will ever be true.

0x08 == 1000 binary
0x02 == 0010 binary



所以你和8的任何东西都不会等于2 ...



所以可能你的意思是0x08两种情况......



但请不要使用魔术数字使用 const int 值 - 名称使其更具可读性或枚举值。它们使您的代码更具可读性,并且更易于维护。



顺便说一句:你在哪里再次看到它们?你有没有检查过你的读入数据中至少有31个字节?


So nothing that you AND with 8 will ever equal 2...

So probably you mean 0x08 in both cases...

But please, don't use "magic numbers" use const int values instead - the names make it a lot more readable, or an enum value. They make your code a lot more readable, and a lot easier to maintain.

BTW: where do you make these visible again? And have you checked there are at least 31 bytes in your read-in data?


我认为这是真的使用

i think this is true to use
serialPort1.Read(uploaddone, 0, uploaddone.Length);

comboBox42.SelectedIndex = -1; comboBox43.SelectedIndex = -1;
comboBox45.SelectedIndex = -1; comboBox46.SelectedIndex = -1;

if ((uploaddone[30] & 0x01) == 0x01)
{
   if ((uploaddone[30] & 0x06) == 0x00) comboBox42.SelectedIndex = 0;
   if ((uploaddone[30] & 0x08) == 0x02) comboBox43.SelectedIndex = 1;
   comboBox45.Hide();comboBox46.Hide();
}

if ((uploaddone[30] & 0x01) == 0x00)
{
   if ((uploaddone[30] & 0x06) == 0x00) comboBox45.SelectedIndex = 0;
   if ((uploaddone[30] & 0x08) == 0x02) comboBox46.SelectedIndex = 1;
   comboBox42.Hide();comboBox43.Hide();
}



。当然在这个位置!

,因为当我们使用comboBox.SelectedIndex = -1;时,这意味着刷新或重置你的组合框作为初始!


when i select manually another value of comboboxes. of course in this position!
because when we use "comboBox.SelectedIndex=-1;", it means refresh or reset your combobox as initial!


这篇关于刷新c#中组合框的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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