473,749 Members | 2,464 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problem regarding to the checklistbox

8 New Member
Hey there,

I have a checkedListBox and a TextBox......Wh en I Checked item in the checkedListBox it shows the value of the respective item in the TextBox.....Whe n 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 programmaticall y

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, 133 views)
Feb 28 '14 #1
1 1211
GAURAV MANUSMAR
8 New Member
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
4635
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 precisely, it updates that table to change the search_path temporarily). With the postgres 7.3 (and 7.4 too) installed on my debian development system, this worked fine. On redhat 9, however, I get an "pg_settings: permission denied" error when my...
1
3876
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 the sum of all digits. the compiler doesnt store the number as given by the user. some of the precision digits are lost or changed (at will!). so by any method, i m unable to reliably calculate the sum of provided number; except i input the...
1
1288
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
1501
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
2329
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 << endl;
2
1765
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
1761
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 required for secure site. The "view Source" is in javascript. Please Help. Thank You.
0
1110
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 this error in one of the pages.. banner.ascx.cs The type or namespace name 'SampleLogin' could not be found (are you missing a using directive or an assembly reference?) both files banner.ascx.cs and SampleLogin.aspx.cs are under the same...
0
1375
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 reasons we will change the extension of the MS Access Database and there is a password for the opening the database). So that we cannot connect to the database. Please give the information regarding this problem as soon as possible...... Thanks &...
1
1225
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 wish to print in one bill after one bill the paper automatically skip to other bill. Here when there is more data in the single bill then we can get the Tear Off Mode. whereas if there is very small data ie 4 lines of data then i cann't able to...
0
8996
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8832
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9566
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9333
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9254
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6800
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3319
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.