就是win from控件的combobox.text赋值没用,在画面上没有显示,只有一种例外,那就是第二位数字为0的数值。
我设定combobox控件的输入设定,限制为数字,在0-100
而我做的另一种combobox控件跟上面完全一样,只是值得限制在0-60.却好使,能赋值输出到画面
求大神帮我看看什么情况,哪个设置的问题?
下面给出代码
出问题的赋值代码
comboBox4.Text = Convert.ToString(systemSet.Kinousentaku_syuonryoupuriseto1);
comboBox7.Text = Convert.ToString(systemSet.Kinousentaku_syuonryoupuriseto2);
comboBox8.Text = Convert.ToString(systemSet.Kinousentaku_syuonryoupuriseto3);
comboBox10.Text = Convert.ToString(systemSet.Kinousentaku_syuonryoupuriseto4);
comboBox9.Text = Convert.ToString(systemSet.Kinousentaku_syuonryoupuriseto5);//52
这是我做的0-100输入限制
private void comboBox7_KeyPress(object sender, KeyPressEventArgs e)
{
if (((int)e.KeyChar < 48 || (int)e.KeyChar > 57) && (int)e.KeyChar != 8)
{
e.Handled = true;
}
}
private void comboBox7_TextChanged(object sender, EventArgs e)
{
if (this.comboBox7.Text == String.Empty)
{
return;
}
if (Convert.ToInt32(comboBox7.Text) > 100)
{
comboBox7.Text = "100";
}
}
之后就是没有问题的0-60的combobox控件,在我眼里这是完全一样的
这是赋值
comboBox6.Text = Convert.ToString(systemSet.Zanjikanbuza1_kidoujikan1);
这是限制
private void comboBox6_KeyPress(object sender, KeyPressEventArgs e)
{
if (((int)e.KeyChar < 48 || (int)e.KeyChar > 57) && (int)e.KeyChar != 8)
{
e.Handled = true;
}
}
private void comboBox6_TextChanged(object sender, EventArgs e)
{
if (this.comboBox6.Text == String.Empty)
{
return;
}
if (Convert.ToInt32(comboBox6.Text) > 60)
{
comboBox6.Text = "60";
}
完全找不出问题,难道是设定问题?
------解决思路----------------------
KeyPress和TextChanged事件没问题。你把赋值的代码注释掉,你会发现输入是符合你的要求的。那么问题就出在你赋值这块了。
问题1:你的赋值代码放在哪里?Load事件或是其他地方?如果在Load里面,那么限制输入的判断就在Load里面。
问题2:你赋的值是否是合法的。加断点看看赋值内容是什么。