473,396 Members | 1,933 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

problem regarding to the checklistbox

Hey there,

I have a checkedListBox and a TextBox......When I Checked item in the checkedListBox it shows the value of the respective item in the TextBox.....When I Checked multiple items in the checkedListBox it shows the values of the respective items in the TextBox separating by {,}"Comma"

Now my question is that when I unchecked the item in the textBox it must remove the value of respective unchecked items from the textBox ......also plz tell me how do i remove "Comma"{,} from the end of the text box programmatically

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Data.SqlClient;
  10. namespace listbox
  11. {
  12.     public partial class Form1 : Form
  13.     {
  14.         public Form1()
  15.         {
  16.             InitializeComponent();
  17.         }
  18.  
  19.  
  20.  
  21.         private void Form1_Load(object sender, EventArgs e)
  22.         {
  23.             SqlConnection connection = new SqlConnection("Data Source=.;Initial Catalog=email_client;Integrated Security=True");
  24.             SqlCommand command = new SqlCommand("Select * FROM address_book ", connection);
  25.  
  26.             try
  27.             {
  28.                 connection.Open();
  29.                 {
  30.                     SqlDataReader drd = command.ExecuteReader();
  31.  
  32.                     while (drd.Read())
  33.                     {
  34.                         this.checkedListBox1.Items.Add(drd.GetString(0).ToString());
  35.  
  36.                     }
  37.                 }
  38.  
  39.             }
  40.             catch (Exception ex)
  41.             {
  42.  
  43.                 MessageBox.Show(ex.Message.ToString());
  44.  
  45.             }
  46.  
  47.             connection.Close();
  48.         }
  49.  
  50.         private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e)
  51.         {
  52.  
  53.                 SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=email_client;Integrated Security=True");
  54.                 con.Open();
  55.                 SqlCommand cmd = new SqlCommand("select * from address_book where name='" + checkedListBox1.Text + "'", con);
  56.                 SqlDataReader dr;
  57.                 dr = cmd.ExecuteReader();
  58.  
  59.  
  60.  
  61.                 while (dr.Read())
  62.                 {
  63.                     textBox1.Text += Convert.ToString(dr["id"] + ",");
  64.                 }
  65.  
  66.  
  67.                 dr.Close();
  68.  
  69.  
  70.         }
  71.  
  72.         private void textBox1_Enter(object sender, EventArgs e)
  73.         {
  74.             ToolTip tt = new ToolTip();
  75.             tt.SetToolTip(textBox1, "sorry");
  76.         }
  77.  
  78.  
  79.  
  80.  
  81.     }
  82. }
  83.  
Attached Images
File Type: jpg Screenshot (17).jpg (37.4 KB, 124 views)
Feb 28 '14 #1
1 1196
Expand|Select|Wrap|Line Numbers
  1. private void checkedListBox1_SelectedIndexChanged(object sender, ItemCheckEventArgs e)
  2. {
  3. StringBuilder stringBuilder = new StringBuilder();
  4.  
  5. foreach (var item in checkedListBox1.CheckedItems)
  6. {
  7. SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=email_client;Integrated Security=True");
  8. con.Open();
  9. SqlCommand cmd = new SqlCommand(string.Format("select * from address_book where name='{0}'", item), con);
  10. SqlDataReader dr = cmd.ExecuteReader();
  11. while (dr.Read())
  12. {
  13. stringBuilder.Append(Convert.ToString(dr["id"] + ","));
  14. }
  15. dr.Close();
  16. }
  17.  
  18. textBox1.Text = stringBuilder.ToString().TrimEnd(',');
  19. }
Mar 1 '14 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Florian G. Pflug | last post by:
Hi I installed a postgres-application (which was developed on debian woody) on red hat 9 today, using the postgres 7.3 rpms from redhad. One of my the triggers uses the pg_settings table (more...
1
by: Shreyas Kulkarni | last post by:
hi there, recently i have got a problem regarding calculation of sum of digits in a floating point or precision number. the weird behaviour of compiler/language is preventing me from calculating...
1
by: Atul Sharma | last post by:
hi friends i m getting problem regarding wht assemblies are? why they r used? & how they r created?
3
by: Mau | last post by:
I have a big problem with the CheckListBox control: if I disable it and the I enable it I loose selection (checking) , why? There is a way to solve this? Tanks M Here some code:
17
by: Ashwin | last post by:
hi guys, i have overloaded the << operator.as shown below. ostream& operator<<(ostream &out, const student &a) { out<<a.idno; out<< " " ; // out<< a.name; out<< " " ; // out<< a.marks...
2
by: Vijendra | last post by:
Hello friends i am facing problem in using icons in toolbar of 256 color or higher in VC++. can any body tell me whats the solution for this problem specialy when my OS is Windows 2000 server.
6
by: ashokfig | last post by:
Hi All, I'm facing problem regarding Accessing secure web page. I tried to connect page through progamming & want access data from web page. I passed Login credentials & also certificate which...
0
by: Adi | last post by:
hi everyone.. i am working on a web application in VS 2005.. i recently converted my application from VS2003 to VS2005.. after the conversion.. when i compiled the application i was starting to get...
0
by: mahesh123 | last post by:
Hi, I am new to use the crystal reports8.0. I am facing the problem regarding the database connection through the ADO Connection. Suppose my database name is "sample.pra"(due to some security...
1
by: mahesh123 | last post by:
Hi, the problem is : while printing the paper moves for A4/Letter and i cann't able to enable the Tear off Mode. I wish to print bill by bill, Pre printed stationery is continious paper, I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.