列表框第一项始终被选中 [英] listbox first item always selected

查看:66
本文介绍了列表框第一项始终被选中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


当我们在下拉列表中选择所有项目时,我有一个下拉列表框中显示的所有项目 工作正常


我想要的时候 所有项目 在列表框中显示总是第一个项目被选中


foreach(ddlcustomer.Items中的ListItem Ist)



                        {



                  ;          if((Ist.Text!=" - ALL - ")&&(Ist.Text!=" - Please Select - "))



                            {



                  ;             列表项LST =新列表项(ddlcustomer.SelectedItem.Text,ddlcustomer.SelectedItem.Value);



       &NBSP ;                       LBoxCustomer.Items.Add(IST);


                            LBoxCustomer.SelectedIndex = 0;  



                                                          
}

                  &NBSP ;       

             &NBSP ;          }


错误显示


不能在DropDownList中选择多个项目。

解决方案

您是在使用Window Form还是WPF。


在对下一项进行选择之前,您需要清除选择。


WPF>> YourControl.UnselectAll();


Win Form>> YourControl.ClearSelected();


然后把你的代码放在你的控件中.SelectedIndex = number ....


还有你的IF情况,你需要使用OR语句,例如如果你想要其中任何一个是真的。

 if((Ist.Text!="  -  ALL  - ")||(Ist.Text!= " - 请选择 - "))



i have a drop down when we select all in dropdown list all item show in listbox  that is working fine

i want when  all item  show in listbox always first item is seleted

foreach (ListItem Ist in ddlcustomer.Items)

                       {

                           if ((Ist.Text != "--ALL--") && (Ist.Text != "-- Please Select --"))

                           {

                               ListItem lst = new ListItem(ddlcustomer.SelectedItem.Text, ddlcustomer.SelectedItem.Value);

                               LBoxCustomer.Items.Add(Ist);

                           LBoxCustomer.SelectedIndex = 0;  

                                                         }
                          
                        }

error show

Cannot have multiple items selected in a DropDownList.

解决方案

Are you working on Window Form or WPF.

You need to clear selection before you do the selection on next item.

WPF >> YourControl.UnselectAll();

Win Form >> YourControl.ClearSelected();

Then put your code YourControl.SelectedIndex = number....

And also for you IF condition, you need to use OR statement e.g. if you want either one is true.

 if ((Ist.Text != "--ALL--") || (Ist.Text != "-- Please Select --"))


这篇关于列表框第一项始终被选中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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