I am going to develop the form like below screen shot. I wrote the code in itemCheck event to insert the checked item text in textbox.
My problem is: if checked items are greater than 2 I want to insert "," (comma) in between the two items.
by selecting the items from checked list box I have to write SQL query.
by removing the selection from checked list box we have to remove that item text from the query in textbox.
Can any one plz help me with code.
Thanks
Murali krishna
Praneeth KumarPosted Jun 7, 2011, 2:09 AM
string query;
if(checkedcount==1)
{
query="select "+checkedvalue[0]+" from tablename";
}
else
{
StringBuilder columns=new StringBuilder();
for(int i=0;i
if(i
columns.Append(checkedValues[i]);
columns.Append(",");
}
else
{
// No more commas needed as this is last column
columns.Append(checkedValue[i]);
}
}
query="select "+columns+" from tablename";
}
execute ur query.
I hope this query helps..This is just a rough code snippet.
Suthish NairPosted Jun 7, 2011, 9:05 AM
Murali krishna AndePosted Jun 7, 2011, 8:19 AM
Problem solved..
Once again thanks
Murali Krishna
Suthish NairPosted Jun 7, 2011, 2:17 AM
Posted Jun 7, 2011, 2:14 AM
private void btn_Click(object sender, EventArgs e)
{
string s = "select ";
for (int i=0;i {
if (checkedListBox1.CheckedItems.Count > i)
if (checkedListBox1.CheckedItems.Count-1 == i)
{
s += checkedListBox1.Items[i].ToString() ;
}
else
{
s += checkedListBox1.Items[i].ToString() + " , ";
}
}
label1.Text = s;
}
Try this.