如何从窗口应用程序中的checkedListBox中获取选定的值 [英] How can get selected value from checkedListBox in window application

查看:70
本文介绍了如何从窗口应用程序中的checkedListBox中获取选定的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有



我的代码如下我从服务器绑定了我的checkedListIntellect。在所有数据库的复选框列表中显示我想从checkListBox中选择已选中的字段我的窗口基础应用程序,如果你的人

Dear All

My code as below i am bind my checkedListIntellect from server.In checkboxlist show from all database know i want to get selected checked field from checkedListBox from my window base application if you people

string db = "";
               foreach (var item in this.checkedListIntellect.CheckedItems)
               {
                   if (checkedListIntellect.SelectedIndex < 0)
                   {

                       db = checkedListIntellect.SelectedItem.ToString();


                   }
               }

           string strIntellectFindTable = "Provider=SQLNCLI10; Data Source=localhost;Initial Catalog=" + db + ";user id=test;password=test";
           checkedListBoxIntellectTable.Items.Clear();





以下代码无法正常工作请告诉我们,如果有人知道解决方案



the below code is not working pls let me know if you people know solution

推荐答案

Quote:

string db =;

foreach(var item in this.checkedListIntellect.CheckedItems)

{

if(checkedListIntellect.SelectedIndex< 0)

{



db = checkedListIntellect.SelectedItem.ToString();





}

}

string db = "";
foreach (var item in this.checkedListIntellect.CheckedItems)
{
if (checkedListIntellect.SelectedIndex < 0)
{

db = checkedListIntellect.SelectedItem.ToString();


}
}





不应该是



Shouldn't that be

int sel = checkedListIntellect.SelectedIndex;
if ( sel >= 0 && checkedListIntellect.GetItemCheckState(sel) == CheckState.Checked)
  db = checkedListIntellect.SelectedItem.ToString();




?


这篇关于如何从窗口应用程序中的checkedListBox中获取选定的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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