如何停止将选定的索引更改为在两个组合中工作 [英] How Do I Stop Selected Index Changed To Work In Two Combo

查看:98
本文介绍了如何停止将选定的索引更改为在两个组合中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个组合框,其中一个包含卷号.第二个包含reg.否.

现在,当我选择卷号时.我应该用reg显示学生详细信息.不.秒那个卷的组合框反之亦然.


问题是到达cmbregno.Text = dr.GetValue(0).ToString())的那一刻

它转到了cmbregno_SelectedIndexChanged方法.并处理该方法.

当我通过regno搜索时.然后执行cmbRoll_SelectedIndexChanged并处理该方法.

I have got 2 combo box one contain roll no. and second contain reg. no.

now when I select roll no. Im supposed to show student detail, with reg. no. in sec. combo box of that roll no. and visa-versa.


Problem is the moment it reach to cmbregno.Text = dr.GetValue(0).ToString())

it went to the cmbregno_SelectedIndexChanged method. and do process the method.

and when I search by regno. than it go the cmbRoll_SelectedIndexChanged and process that method.

How to stop other method to run when it came to that point of reading value.

推荐答案

使用bool variabe来说明您的代码是否在更改组合索引,像

Use a bool variabe stating if is your code who is changing the combo index,something like

bool codeChanging=false;

cmbregno_SelectedIndexChanged(sender...)
{
    if (!codeChanging)
    {
       //do whatevere you are doing here now
       codeChanging=true;
       cmbrollno= dr.GetValue(0).ToString())
     }
     else
     {
        codeChanging=false;
     }

}

cmbrollno_SelectedIndexChanged(sender...)
{
    if (!codeChanging)
    {
       //do whatevere you are doing here now
       codeChanging=true;
       cmbregno= dr.GetValue(0).ToString())
     }
     else
     {
        codeChanging=false;
     }

}


这篇关于如何停止将选定的索引更改为在两个组合中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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