473,699 Members | 2,475 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, 131 views)
Feb 28 '14 #1
1 1210
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
4613
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
3873
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
1285
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
1497
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
2321
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
1762
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
1760
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
1107
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
1373
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
1221
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
9192
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...
0
9054
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8940
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
8895
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
6546
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
5879
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4390
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.