Click here to Skip to main content
15,881,424 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
C#
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
Posted

1 solution

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

db = checkedListIntellect.SelectedItem.ToString();


}
}


Shouldn't that be
C#
int sel = checkedListIntellect.SelectedIndex;
if ( sel >= 0 && checkedListIntellect.GetItemCheckState(sel) == CheckState.Checked)
  db = checkedListIntellect.SelectedItem.ToString();

?
 
Share this answer
 
Comments
Arjunwalmiki 3-Feb-14 5:04am    
string db = "";
foreach (var item in this.checkedListIntellect.CheckedItems)
{
if (checkedListIntellect.SelectedIndex < 0)
{

db = checkedListIntellect.SelectedItem.ToString();


}
}

if (checkedListIntellect.SelectedIndex < 0)
This condition is false
so this line is Null(db = checkedListIntellect.SelectedItem.ToString();)
Arjunwalmiki 3-Feb-14 5:09am    
System.Data.DataRowView

and in this code

int sel = checkedListIntellect.SelectedIndex;
if ( sel >= 0 && checkedListIntellect.GetItemCheckState(sel) == CheckState.Checked)
{
db = checkedListIntellect.SelectedItem.ToString();
}
i am not get selected value pls help on place of get selected value System.Data.DataRowView

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900